我是python的新手,我需要从文本文件中读取数字并将其按顺序传递到列表中,这是我想出的:
liste = []
with open("MDATX3.014") as fa:
lines = fa.readlines()
for line in lines:
words = line.split()
for word in words:
liste.append(word)
print(liste)
答案 0 :(得分:2)
如果不想在中间添加新值时看到其中间值,则应该在循环之外print(liste)
:
liste = []
with open("MDATX3.014") as fa:
lines = fa.readlines()
for line in lines:
words = line.split()
for word in words:
liste.append(word)
print(liste)