the inspect thing

castironpi at gmail.com castironpi at gmail.com
Thu May 10 03:43:34 EDT 2007


-----the code:
class A:
	b=2

import inspect
print inspect.getsource(A)

class A:
	c=2
print inspect.getsource(A)

-----unavailable from the console, but gets you:
class A:
        b=2

class A:
        b=2

One thought is, in inspect, could at least:
def findsource(object):
   #snip
        if candidates:
            # this will sort by whitespace, and by line number,
            # less whitespace first
            candidates.sort()
            return lines, candidates[0][1]
be
            return lines, candidates[-1][1]
to get the most recent?

Why no cl_firstlineno in the object for the class, or access to the
code?-acb




More information about the Python-list mailing list