Re: code of a function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christian Heimes

    Re: code of a function

    Dark Wind schrieb:
    Hi,
    >
    Is there any command in Python which gives the code for a function like just
    typing the name of a function (say svd) in R returns its code.
    Yes, it's posible to retrieve the source code IFF the function is
    implemented in Python and the .py file is available, too.
    >>print inspect.getsour ce(inspect.gets ource)
    def getsource(objec t):
    """Return the text of the source code for an object.

    The argument may be a module, class, method, function, traceback, frame,
    or code object. The source code is returned as a single string. An
    IOError is raised if the source code cannot be retrieved."""
    lines, lnum = getsourcelines( object)
    return string.join(lin es, '')

Working...