On Wed, Jun 23, 2010 at 1:53 AM, Peng Yu <pengyu...@gmail.com> wrote:
> It seems I don't completely understand how getsource works, as I
> expect that I should get the source code of class A. But I don't.
> Would you please let me know what I am wrong?

If you "read" the documentation carefully:

"""
   getsource(object)
        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.
"""

This "does not" include an object / instance (whichever you prefer).

$ python main.py
class A:
 pass


$ cat main.py
import inspect

class A:
 pass

a=A()

print inspect.getsource(a.__class__)

cheers
James

-- 
--
-- "Problems are solved by method"
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to