Access input line on NameError?

Michael Hudson mwh at
Mon Dec 3 06:21:12 EST 2001

gb at writes:

> Can I get access to the offending text line of the input when I take a
> NameError exception? I see that it is available on a SyntaxError but I
> can't seem to find it on a NameError.

I think you can use the traceback module to do this.  Or if you like
getting your hands dirty, use sys.exc_info() and grub around with
frame and code objects yourself.


  One of the great skills in using any language is knowing what not
  to use, what not to say.  ... There's that simplicity thing again.
                                                       -- Ron Jeffries

More information about the Python-list mailing list