471,052 Members | 1,188 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,052 software developers and data experts.

List code of function in interpreter

A simple question.

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

Thanks

Erwin
Jul 18 '05 #1
1 1412
a9******@unet.univie.ac.at 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
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Helge | last post: by
5 posts views Thread by Diez B. Roggisch | last post: by
6 posts views Thread by Bernhard | last post: by
35 posts views Thread by Thierry Loiseau | last post: by
1 post views Thread by yawgmoth7 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.