我有一个 .txt 文件,如下所示:
abcd this is the header
more header, nothing here I need
***********
column1 column2
========= =========
12.4 A
34.6 mm
1.3 um
=====================
footer, nothing that I need here
***** more text ******
我正在尝试读取列中的数据,每一个都进入它自己的列表,col1 = [12.4, 34.6, 1.3] 和 col2 = ['A', 'mm', 'um']。
这是我到目前为止所拥有的,但是当我运行代码时唯一返回的是“无”:
def readfile():
y = sys.argv[1]
z = open(y)
for line in z:
data = False
if data == True:
toks = line.split()
print toks
if line.startswith('========= ========='):
data = True
continue
if line.startswith('====================='):
data = False
break
print readfile()
有什么建议么?