[IPython-dev] Getting executed code

Fernando Perez Fernando.Perez at colorado.edu
Tue Nov 29 15:22:11 EST 2005


Frédéric Mantegazza wrote:
> Hello,
> 
> Is there a way to retreive the currently executed code ? The ipshell.buffer 
> contains the code, but in the case of a multiline code, how can I know what 
> is the current line executed, in my custom exception handler ?

At that point, you need to use python's exception inspection machinery. 
IPython feeds entire blocks for execution to the interpreter, so it can't know 
at what line the error occurred.  But that information is stored in the 
traceback objects, so you can retrieve it.  Look at ultraTB.py for details of 
how ipython builds that information for display.

Cheers,

f




More information about the IPython-dev mailing list