我有一个文本文件,类似于这样,有几个5000行:
5.6 4.5 6.8 "6.5" (new line)
5.4 8.3 1.2 "9.3" (new line)
最后一个术语是被双引号括起来的数字。
我的目标是使用Python(如果可能的话),将这四列分配给双精度变量。但主要问题是最后一个术语,我找不到方法去掉双引号得到数字,这在Linux中可能吗?
这是我尝试过的:
#!/usr/bin/python
import os,sys,re,string,array
name=sys.argv[1]
infile = open(name,"r")
cont = 0
while 1:
line = infile.readline()
if not line: break
l = re.split("\s+",string.strip(line)).replace('\"','')
cont = cont +1
a = l[0]
b = l[1]
c = l[2]
d = l[3]