Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Tracebacks for `exec`ed code?

Reply
Thread Tools

Tracebacks for `exec`ed code?

 
 
Adam Atlas
Guest
Posts: n/a
 
      04-29-2007
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?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=
Guest
Posts: n/a
 
      04-29-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
 
Reply With Quote
 
 
 
 
brzrkr0@gmail.com
Guest
Posts: n/a
 
      04-30-2007
On Apr 29, 2:40 am, "Martin v. L÷wis" <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
catching all tracebacks Timothy Smith Python 0 10-05-2005 11:54 PM
getting tracebacks from traceback objects Michael P. Soulier Python 1 06-24-2005 10:56 AM
How should threads be terminated? (related to 'Help with thread related tracebacks') Maxwell Hammer Python 7 06-18-2005 04:20 PM
Help with thread related tracebacks Maxwell Hammer Python 0 06-16-2005 05:50 AM
tracebacks in embedded python =?ISO-8859-1?Q?Mike_M=FCller?= Python 1 07-09-2003 03:38 PM



Advertisments