Created
April 26, 2014 03:58
-
-
Save iffy/11311366 to your computer and use it in GitHub Desktop.
How do I get inspect.getsource to get the right source?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A(object): | |
def foo(self): | |
pass | |
class A(object): | |
def bar(self, a, b, c): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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