How can I store from a file to array in Python?
This question already has an answer here:
This is one way to achieve that:
with open('filename') as file:
lines = [i.strip() for i in file]
If you want your list to contain the numbers ( int ) instead of strings the following code will achieve this:
with open('seq.txt') as f:
numbers = [int(i) for i in f]
Thanks to Ninja Puppy♦ to improve the code.
链接地址: http://www.djcxy.com/p/42354.html上一篇: 从python文件中逐行读取