读取txt文件中的某一列:
[int(l.split()[0]) for l in open(“a.txt”)]
但是读不了最后一列,出现:IndexError: list index out of range的问题。
参考:http://www.cnblogs.com/xuxn/archive/2011/07/27/read-a-file-with-python.html
讲的很详细,
对于这样的问题:每行有3列,依次读取,空格间隔,分别将每行的不同列存到不同的数组a[],b[].c[]。解法如下:
name = [[],[],[]]
with open('circle.txt') as f:
for line in f:
for each in enumerate(line.split()):
name[each[0]].append(float(each[1]))
a,b,c = name