Python文本操作之读取浮点数方法源码示例,,import refp


import refp = open('c:/1.txt', 'r')s = fp.readline()print(s)aList = re.findall('([-+]?\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?',s) #使用正规表达式搜索字符串print(aList)#www.iplaypy.comfor ss in aList:    print(ss[0]+ss[2])    aNum = float((ss[0]+ss[2]))    print(aNum)fp.close()文件内容: 12.540  56.00  1.2e2 -1.2E2 3.0e-2 4e+3

编橙之家文章,

评论关闭