source code of a function object

Erno Kuusela erno-news at erno.iki.fi
Thu Nov 13 15:53:09 CET 2003


Fernando Rodriguez <frr at easyjob.net> writes:

> Hi,
> 
> Is ti possible to get the source code of a given function object? O:-)
> 
> TIA

>>> import pickle, inspect
>>> print inspect.getsource(pickle.dumps)
def dumps(obj, protocol=None, bin=None):
    file = StringIO()
    Pickler(file, protocol, bin).dump(obj)
    return file.getvalue()

>>>

  -- erno




More information about the Python-list mailing list