Tracebacks for `exec`ed code?

brzrkr0 at gmail.com brzrkr0 at gmail.com
Mon Apr 30 19:01:28 CEST 2007


On Apr 29, 2:40 am, "Martin v. Löwis" <mar... at v.loewis.de> wrote:
> 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

You could also write the code you want to execute to a temporary file,
then use execfile() on that file.

-Casey




More information about the Python-list mailing list