I'm building a debugging tool.
IPython lets me do stuff like
MyCls??
And it will show me the source.
isclass(): The isclass() method returns True if that object is a class or false otherwise. When it is combined with the getmembers() functions it shows the class and its type. It is used to inspect live classes.
We use the getsource() method of inspect module to get the source code of the function. Returns the text of the source code for an object. The argument may be a module, class, method, function, traceback, frame, or code object. The source code is returned as a single string.
To list all the attributes of an object, use the built-in dir() function. It returns a long list of attribute names, that is, method and variable names of the object. There is a bunch of automatically generated attributes in any Python class.
sys.modules[MyCls.__module__].__file__
or
inspect.getsourcefile(MyCls)
There are more __xxx__
attributes on various objects you might find useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With