Given the Python class, how can I check and find the place in my code where it is defined?

I am creating a debugging tool.

IPython lets me do things like

MyCls??

And he will show me the source.

+5
source share
4 answers
sys.modules[MyCls.__module__].__file__

or

inspect.getsourcefile(MyCls)

More __xxx__attributes on various objects that may be useful to you.

+8
source

Here is a pretty good overview of the many features of Python metadata:

http://www.ibm.com/developerworks/library/l-pyint.html

+4
source
+2

, inspect.getsource - ; ( , ..), . inspect, URL-, getsource. , , , , try/except, , , . ( , , , import inspect , inspect).

+2

All Articles