List and array code?

D

derek / nul

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 or
array.

Any pointers most appreciated.

Derek
 
M

mackstann

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 or
array.

Any pointers most appreciated.

f = file("foobar.txt", "r")

myListOfLines = f.readlines()

Or if you really don't need to make list, but just want to loop through
the lines in a file:

f = file("foobar.txt", "r")

for line in f:
print line
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,095
Messages
2,570,616
Members
47,232
Latest member
helpplease!

Latest Threads

Top