Keys To The Kingdom

Tim Daneliuk tundra at tundraware.com
Tue Jul 10 20:40:01 CEST 2001


Alex Martelli wrote:
> 
> "Tim Daneliuk" <tundra at tundraware.com> wrote in message
> news:3B4AC204.80941297 at tundraware.com...
> > Tim Hammerquist wrote:
> > >
> > >
> > > This works for me:
> > >
> > >     try:
> > >         input = raw_input()
> > >     except KeyboardInterrupt:
> > >         # handle Ctrl-C
> > >
> > > The only difference I see is the capital 'B' you have in
> > > 'KeyboardInterrupt'.  Change it to lowercase and see what happens.
> >
> > (Whoops, I spelled it wrong here, but correctly in my program.)
> >
> > This code fragment works fine under Unix (FreeBSD 4.3) but not under
> > Windows 2000.  Is this a known bug or is there some magic I'm missing?
> 
> It seems to me (trying under NT4) that raw_input() is generating
> an EOFError on Ctrl-C (or Ctrl-Break) rather than the exception
> you (reasonably expect), i.e. KeyboardInterrupt.  Maybe try an
>     except (KeyboardInterrupt, EOFError):
>         # whatever
> to catch both...?  Of course, on Unix EOFError would happen if
> the user hit Ctrl-D rather than Ctrl-C, and on Windows also on
> Ctrl-Z followed by a return, but...
> 
> Alex

Nope, the traceback is definitely showing a KeyboardError.  I did what
you suggested just to be sure, but still no go.  What's weird is that
the code below works on unix (freebsd) and IDLE on win2k, but not python itself
on win2k...

while 1:
    try:
        x = raw_input().upper()
        print x
    except KeyboardInterrupt:
        print "Leaving Dodge...\n"
        break
-- 
------------------------------------------------------------------------------
Tim Daneliuk
tundra at tundraware.com



More information about the Python-list mailing list