[Tutor] Why different behaviours?
Sat, 27 Oct 2001 17:01:17 +0100
> import string, sys
> icon.txt', 'r')
> for line in f.readline():
readline returns a string, line will therefore take the value
of each char in the string.
> Also, what would be the way to read line after line until end
> of file. How to detect end of file when reading a sequential
> file this way?
If its a short-medium file use:
for line in f.readlines(): # note plural!
or for long files:
for line in f.xreadlines(): # x stops it all being read at once
line = f.readline()
There are other variations. For more words explaining
whats going on try my tutor at:
look under the files topic...