List and array code?
sross at connectmail.carleton.ca
Sun Aug 24 04:16:54 CEST 2003
"derek / nul" <abuseonly at sgrail.org> wrote in message
news:ss6gkvo87qn5eu279gsct60c1id8fmb6hb at 4ax.com...
> Is there any list or array code that can load lines from a file?
> ie what I would like is to open a file and load line by line into a list
There are several ways to do this:
# list comprehension
lines = [line for line in file("your/file/name/here")]
lines = file("your/file/name/here").readlines()
# build list from iterator
lines = list(file("your/file/name/here"))
# for loop
lines = 
for line in file("your/file/name/here"):
More information about the Python-list