Tracebacks for `exec`ed code?

Discussion in 'Python' started by Adam Atlas, Apr 29, 2007.

  1. Adam Atlas

    Adam Atlas Guest

    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?
     
    Adam Atlas, Apr 29, 2007
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=, Apr 29, 2007
    #2
    1. Advertising

  3. Adam Atlas

    Guest

    On Apr 29, 2:40 am, "Martin v. Löwis" <> 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
     
    , Apr 30, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Mike_M=FCller?=

    tracebacks in embedded python

    =?ISO-8859-1?Q?Mike_M=FCller?=, Jul 9, 2003, in forum: Python
    Replies:
    1
    Views:
    340
    Thomas Heller
    Jul 9, 2003
  2. Maxwell Hammer

    Help with thread related tracebacks

    Maxwell Hammer, Jun 16, 2005, in forum: Python
    Replies:
    0
    Views:
    312
    Maxwell Hammer
    Jun 16, 2005
  3. Maxwell Hammer
    Replies:
    7
    Views:
    656
    Peter Hansen
    Jun 18, 2005
  4. Michael P. Soulier

    getting tracebacks from traceback objects

    Michael P. Soulier, Jun 24, 2005, in forum: Python
    Replies:
    1
    Views:
    381
    Kent Johnson
    Jun 24, 2005
  5. Timothy Smith

    catching all tracebacks

    Timothy Smith, Oct 6, 2005, in forum: Python
    Replies:
    0
    Views:
    283
    Timothy Smith
    Oct 6, 2005
Loading...

Share This Page