Introspection
examine something, typically an object, at runtime.
dir()
dir(object)
['__class__',
'__delattr__',
'__dir__',
'__doc__',
'__eq__',
'__format__',
'__ge__',
'__getattribute__',
'__gt__',
'__hash__',
'__init__',
'__init_subclass__',
'__le__',
'__lt__',
'__ne__',
'__new__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__sizeof__',
'__str__',
'__subclasshook__']
type checking
type(int)
type
int.__class__
type
isinstance(4, int)
True
issubclass(int, object)
True
inspect
import inspect
inspect.isclass(int)
True
def foo():
'''foo comments'''
pass
inspect.getsource(foo)
"def foo():\n '''foo comments'''\n pass\n"
[attr for attr in dir(inspect) if attr.startswith('is')]
['isabstract',
'isasyncgen',
'isasyncgenfunction',
'isawaitable',
'isbuiltin',
'isclass',
'iscode',
'iscoroutine',