[英]appending data from a text file into a list in python
i am new to python and i need to read numbers from a text file and pass those in order into a list here is what i came up with : 我是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)
You should print(liste)
outside the loop if you don't want to see its intermediate values while it is being appended with new values: 如果在追加新值时不希望看到它的中间值,则应该在循环外
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.