Is it possible to get the erroneous variable when getting a NameError exception?

Dotan Barak dotanba at gmail.com
Fri Dec 25 14:31:15 EST 2009


On 25/12/2009 19:27, Gary Herron wrote:
> Dotan Barak wrote:
>
> Recover the exception, and examine the tuple of args or the message 
> string.
> >>> try:
> ...         eval("my_number < 10", {"__builtins__":None}, {})
> ... except NameError,e:
> ...         print e.args
> ...         print e.message
> ...
> ("name 'my_number' is not defined",)
> name 'my_number' is not defined
>
First of all, thank - I really appreciate your response.
:)

I must admit that i don't like the idea of parsing a string (if tomorrow 
the format of the message will change,
i will be in a deep trouble ...).

Is there is another way which doesn't involve string parsing?

Thanks
Dotan



More information about the Python-list mailing list