very newbie question about exception handling
Ricardo Aráoz
ricaraoz at gmail.com
Mon Dec 24 17:26:46 EST 2007
Louis.Soninhu at gmail.com wrote:
> code sample:
> ----------------------------------------------
> i=input()
> try:
> x=int(i)
> print "you input an integer"
> except ValueError:
> print "you must input an integer"
> ------------------------------------------------
> when I input a value like, b
> I got the traceback message instead of proper exception handling:
>
> NameError: b is not defined
>
> I also tried
> ------------------------------------------
> try: x=int(i)
> except ValueError: print "something"
> except NameError: pting "something"
> else: print "something"
> ----------------------------------------------------
> It still couldn't capture the exception, just the same traceback error
> msg.
>
> I'm really confused, any suggestions please?
>
Yes, you must use raw_input() (check the manual on "input()").
More information about the Python-list
mailing list