源文件如下:
12
12 124
34 54 123123123
12312412345
代码如下:
List = []
while 1:
a = file.readline()
if not string:
break
else:
List.append(list(map(int,string.split())))
count = count + 1
print(List)
以上代码输出结果会将空白行也在list里输出来,如何使其不要出现在list中
下面两位的READLINES方法我已经试过了,并没有用。。空白行还是会产生一个空的list。。。
用
for line in file.readlines():
if line:
....
f=open(filename)
for line in f.readlines();
process(line)
f.close()
参考自:
python 文件操作二 http://www.data.5helpyou.com/article79.html