By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

Tracebacks for `exec`ed code?

P: n/a
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?

Apr 29 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Apr 29 '07 #2

P: n/a
On Apr 29, 2:40 am, "Martin v. Lwis" <mar...@v.loewis.dewrote:
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

Apr 30 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.