将excel或者txt文件的每行转换成列表(list)
2021-07-07 本文已影响0人
大大的世界和小小的人儿
方法一:
with open('filename','r') as f: #读入文件
L = [i.strip().split() for i in f] #strip()函数,默认删除字符串头和尾的空白字符
print(L)
也可以这样读入文件:
f= open(r'filename','r') #读入文件
L = [i.strip().split() for i in f]
print(L)
f.close()