[Tutor] EOF problems

Christopher Spears cspears2002 at yahoo.com
Wed Jan 28 19:48:45 EST 2004


I've been trying to write a script that uses a while
function and raw_input.  Basically, I want to be able
to keep typing input until I type in an EOF signal. 
Here is the script: 

s = []

while s != "":
    s = raw_input ('Type a string:')

My instructor claims that Ctrl-Z in Windows is the
equivalent of an EOF.  However, this is not what I
have discovered.  Ctrl-Z is the undo command in IDLE. 
Instead, I used Ctrl-C, which is the copy command. 
Since there was an empty string, the script stopped. 
Here is the result:

>>> 
Type a string:asdfjk;l
Type a string:asdfj;
Type a string:asdfj

Traceback (most recent call last):
  File "C:\Documents and Settings\Christstopher
Spears\My Documents\python\unit7question2.py", line 4,
in -toplevel-
    s = raw_input ('Type a string:')
TypeError: object.readline() returned non-string
>>> 

Ok, so the script works, but what is the EOF signal in
IDLE?  Reading the docs, I seemed to gather that when
reading a file, Python sees an empty string as the
EOF.  Am I wrong?  Is there some variable that can be
used to signal EOF to Python?  I have already tried
eof.

-Chris





More information about the Tutor mailing list