By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,327 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

List code of function in interpreter

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.