Skip to content

Instantly share code, notes, and snippets.

@iffy
Created April 26, 2014 03:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iffy/11311366 to your computer and use it in GitHub Desktop.
Save iffy/11311366 to your computer and use it in GitHub Desktop.
How do I get inspect.getsource to get the right source?
class A(object):
def foo(self):
pass
class A(object):
def bar(self, a, b, c):
pass
import inspect
class Parent(object):
def source1(self):
class A(object):
def foo(self):
pass
print inspect.getsource(A)
def source2(self):
class A(object):
def bar(self, a, b, c):
pass
print inspect.getsource(A)
parent = Parent()
parent.source1()
parent.source2()
# python foo.py
class A(object):
def foo(self):
pass
class A(object):
def foo(self):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment