[Tutor] file I/O
Michael P. Reilly
arcege@speakeasy.net
Wed, 11 Jul 2001 16:31:16 -0400 (EDT)
kevin parks wrote
>
> Hi. I am a little confused as to why this hangs when i run it. I am trying to
Off hand, I would say it is the end condition. The readline method
returns an empty string (false) when the end of file is reached, not a
string with a space.
> done = 0
> while not done:
> aLine = infile.readline()
> if aLine != " ":
if aLine != "": # not at EOF, so write out
> f.write(aLine + '\n')
> else:
> done = 1
Also, readline returns a whole line of text, including the newline.
You probably do not need to append an additional newline.
-Arcege
--
+----------------------------------+-----------------------------------+
| Michael P. Reilly | arcege@speakeasy.net |