Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > List code of function in interpreter

Reply
Thread Tools

List code of function in interpreter

 
 
a9605473@unet.univie.ac.at
Guest
Posts: n/a
 
      04-16-2004
A simple question.

Is it possible in the python (or ipython) interpreter to
review the source code of a self defined function?

Thanks

Erwin
 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      04-16-2004
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> A simple question.
>
> Is it possible in the python (or ipython) interpreter to
> review the source code of a self defined function?


That depends. The source is actually "lost" in at least
one sense, because Python is compiled to bytecode (similar
in some ways to how Java works) behind the scenes, and the
interpreter executes this bytecode and not the source.

On the other hand, the source file is still right there, usually,
and if you are looking for a programmatic way of finding it
and listing it, I believe the inspect module is what you are
looking for: http://docs.python.org/lib/module-inspect.html

Another and much less suitable (I suspect) option for you is to
disassemble the function using the dis module.

-Peter
 
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
How does one view the source of function defined in the interpreter? mattc Python 1 01-29-2009 07:04 PM
How do I output a list like the interpreter do? noagbodjivictor@gmail.com Python 3 05-04-2007 12:28 AM
Python embedded interpreter: how to initialize the interpreter ? ycollet@freesurf.fr Python 3 01-03-2007 01:00 AM
Debugging of Python code in embedded interpreter TK Python 1 11-30-2005 04:05 PM
write a function such that when ever i call this function in some other function .it should give me tha data type and value of calling function parameter komal C++ 6 01-25-2005 11:13 AM



Advertisments