On Tue, Jun 22, 2010 at 9:53 AM, Peng Yu <pengyu...@gmail.com> wrote:
> Hi,
>
> 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?
>
> $ cat main.py
> #!/usr/bin/env python
>
> import inspect
>
> class A:
>  pass
>
> a=A()
>
> print inspect.getsource(a)

You passed in an instance of the class, not the class itself.  The
following will work:

print inspect.getsource(A)

As will:

print inspect.getsource(a.__class__)

Cheers,
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to