List code of function in interpreter

Discussion in 'Python' started by a9605473@unet.univie.ac.at, Apr 16, 2004.

  1. Guest

    A simple question.

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

    Thanks

    Erwin
    , Apr 16, 2004
    #1
    1. Advertising

  2. Peter Hansen Guest

    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
    Peter Hansen, Apr 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TK
    Replies:
    1
    Views:
    320
    Scott David Daniels
    Nov 30, 2005
  2. Bram Stolk
    Replies:
    2
    Views:
    277
    Sion Arrowsmith
    May 11, 2006
  3. Replies:
    3
    Views:
    748
    Ziga Seilnacht
    Jan 3, 2007
  4. Replies:
    3
    Views:
    231
  5. mattc
    Replies:
    1
    Views:
    260
    Terry Reedy
    Jan 29, 2009
Loading...

Share This Page