Given a class or function, is there a way to find the full path to the module where it is originally defined? (Ie using def xxx or class xxx .)
I know there is sys.modules[func.__module__] . However, if func imported into the __init__.py package, then sys.modules will simply be redirected to this __init__.py , because the function has been moved to this namespace, as I understand it.
Specific example:
>>> import numpy as np >>> import sys >>> np.broadcast.__module__ 'numpy' >>> sys.modules[np.broadcast.__module__] <module 'numpy' from '/Users/brad/.../site-packages/numpy/__init__.py'>
Obviously broadcast not defined in __init__.py ; it is simply entered into the namespace with one of these from module import * statements.
It would be nice to see where np.broadcast defined in the source (regardless of the file extension, whether it be .c or .py). Is it possible?
source share