[Tutor] Exception not working as expected?
Alan Gauld
alan.gauld at yahoo.co.uk
Fri Mar 1 11:16:21 EST 2019
I don't have python2 on my win10 PC and it works as expected on python 3.
I suspect study of Eryk's post is your best bet. When it comes to the
innards of Windows he is our local guru.
On 1 Mar 2019 2:24 pm, Chip Wachob <wachobc at gmail.com> wrote:
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
<[1]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
[2]http://www.alan-g.me.uk/
[3]http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
[4]http://www.flickr.com/photos/alangauldphotos
_______________________________________________
Tutor maillist** -** [5]Tutor at python.org
To unsubscribe or change subscription options:
[6]https://mail.python.org/mailman/listinfo/tutor
References
Visible links
1. mailto:tutor at python.org
2. http://www.alan-g.me.uk/
3. http://www.amazon.com/author/alan_gauld
4. http://www.flickr.com/photos/alangauldphotos
5. mailto:Tutor at python.org
6. https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list