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. Advertisements

  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. Advertisements

  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. Advertisements

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. Hal Vaughan
    Replies:
    11
    Views:
    1,530
    Gordon Beaton
    May 22, 2006
  2. =?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:
    435
    Thomas Heller
    Jul 9, 2003
  3. tedsuzman
    Replies:
    2
    Views:
    7,574
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    676
    Duncan Booth
    Jul 22, 2004
  5. Maxwell Hammer

    Help with thread related tracebacks

    Maxwell Hammer, Jun 16, 2005, in forum: Python
    Replies:
    0
    Views:
    423
    Maxwell Hammer
    Jun 16, 2005
  6. Maxwell Hammer
    Replies:
    7
    Views:
    846
    Peter Hansen
    Jun 18, 2005
  7. Guillermo Riojas
    Replies:
    0
    Views:
    329
    Guillermo Riojas
    Nov 26, 2010
  8. Random Task
    Replies:
    12
    Views:
    1,167
    Joe Smith
    Dec 4, 2005
Loading...