List code of function in interpreter

A

a9605473

A simple question.

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

Thanks

Erwin
 
P

Peter Hansen

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top