[Tutor] Exception not working as expected?

Chip Wachob wachobc at gmail.com
Fri Mar 1 09:24:05 EST 2019


Alan,

Thanks.  Once again, a case of not finding a tree in the forest...  One of
these days I'll remember to KISS and try some SIMPLE experimentation...


So I did your experiment with just the single line raw_input('>'), ran it,
and used Ctrl-C to exit.  Traceback shown below.


C:\Temp_Python\Exception>python rawsimple.py
>Traceback (most recent call last):
  File "rawsimple.py", line 1, in <module>
    raw_input('>')


C:\Temp_Python\Exception>



Note that I ran the same code on a Linux machine and did get the name of
the exception as you expected (KeyboardInterrupt).  And I was able to make
a slightly longer script (again, as suggested) and got the desired results..

Open to suggestions on how to capture the exception who's name isn't
displayed...

I'm still attempting to get my head around Eryk's post and perhaps that
explains why there's no exception listed.


On Thu, Feb 28, 2019 at 8:34 PM Alan Gauld via Tutor <tutor at python.org>
wrote:

> On 28/02/2019 21:03, Chip Wachob wrote:
>
> > it does work properly in Linux.  So I'm guessing I need to test for a
> > different exception along with the KeyboardInterrupt??
>
> Don't guess, test.
>
> Write a single line script
>
> raw_input('> ')
>
> Run it in a console.
> Hit Ctrl-C while it waits for input.
> See what the stack trace says is the exception
> Edit your script
>
> try:
>   raw_input('> ')
> except <whatever e3xception you saw previously>:
>   print "I got it that time!"
>
> run the new script.
> Did it work? Hooray! Transfer to the main script.
> If not come back here armed with tracebacks...
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list