raw_input bug only in cygwin python

Richard Walkington richard at stockcontrol.net
Fri Apr 19 13:14:44 EDT 2002


David Carson wrote:

>Tim Roberts <timr at probo.com> wrote in message news:<kuavbukpa505nru9g6kfivo3bfrtirda05 at 4ax.com>...
>  
>
>>davidccarson at hotmail.com (David Carson) wrote:
>>
>>    
>>
>>>Here is a snippet of code:
>>>
>>>01: #!/usr/bin/env python
>>>02: 
>>>03: list = []
>>>04: while 1:
>>>05:     try:
>>>06:         stuff = raw_input("[^D to exit]: ")
>>>07:     except EOFError:
>>>08:         print "got EOF"
>>>09:         break
>>>10:     list.append(stuff)
>>>11: 
>>>12: raw_input("bang! ")
>>>
>>>
>>>This works on every Python environment I've tried but cygwin (Win2000
>>>-- I haven't got NT to try it):
>>> Python 2.2 (#1, Dec 31 2001, 15:21:18)
>>> [GCC 2.95.3-5 (cygwin special)] on cygwin
>>>
>>>In this environment, the EOFError is caught.  Then the "bang! " prompt
>>>for the raw_input() outside the loop is printed, but immediately the
>>>program exits with an uncaught EOFError.
>>>
>>>This code works with:
>>>- ActiveState Python, 2.1 on Win2000
>>>- python 2.2 on Mandrake
>>>- python 1.5.2 on RedHat
>>>and everywhere else, I'm sure.
>>>
>>>Is this a known problem with cygwin?
>>>      
>>>
>>I wouldn't call it a problem with cygwin, I'd call it "relying on
>>unspecified behavior".  Ctrl-D is end of file; the ability to read past EOF
>>is not promised anywhere in the docs.
>>    
>>
>
>
>Ah, I see.  However, I've seen this technique recommended in several
>docs/tutorials.  Also, the docs do promise raw_input() will raise
>EOFError when EOF is read.  So, if it is true that I'm relying on
>unspecified behavior, my question is: How do I make this code
>reliable?  Is there a simple way to clear the EOF indication on stdin?
> I hope there is a good way, because I like this kind of input loop
>much better than the "type 'q' to quit" ilk.
>
>Thanks,
>David
>  
>

I don't see anything wrong with your code. I wouldn't have throught the 
second raw_input should receive an EOF. I've also seen this technique 
used in tutorials etc.

Regards
Richard Walkington






More information about the Python-list mailing list