Reputation: 45
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 :
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)
and i had the result like this
Upvotes: 3
Views: 803
Reputation: 106425
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:
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)
Upvotes: 2