Source From Here
Question
Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.
How-To
You can use the inspect module, like this:
- A.py
- B.py
Then enter Python Interactive Mode:
Question
Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance off C.
How-To
You can use the inspect module, like this:
- A.py
- class A(object):
- def __init__(self):
- print "Class A constructor"
- class B(object):
- def __init__(self):
- print "Class B constructor"
沒有留言:
張貼留言