Tracebacks for `exec`ed code?

"Martin v. Löwis" martin at v.loewis.de
Sun Apr 29 05:40:38 EDT 2007


Adam Atlas schrieb:
> Is it possible to make more traceback information available for
> exceptions code dynamically run via `exec`? Normally it just says
> things like "File '<string>', line 3, in ?", which is not very
> helpful. I'm looking for a way for it to show the line of source code
> below it, like it would for an exception in a physical file. Is this
> possible?

Yes. You will need to print the traceback yourself; see
traceback.print_tb for an example.

Regards
Martin



More information about the Python-list mailing list