Putting a line from a text file into a variable, then moving to next line
Michal Bozon
bozonm at vscht.cz
Sun Oct 7 08:45:19 EDT 2007
On Sun, 07 Oct 2007 12:00:44 +0000, Vernon Wenberg III wrote:
> I'm not really sure how readline() works. Is there a way to iterate
> through a file with multiple lines and then putting each line in a
> variable in a loop?
There are always more ways how to do it.. one of them is:
f = open(filename)
for line in f:
# you may then strip the newline:
line = line.strip('\n')
# do anything you want with the line
f.close()
More information about the Python-list
mailing list