Finding the name of an object's source file

Gregory Ewing greg.ewing at canterbury.ac.nz
Tue Jun 6 18:35:37 EDT 2017


Matt Wheeler wrote:
>>>>import importlib, os
>>>>importlib.import_module(os.path.split.__module__).__file__
> 
> '/Users/matt/.pyenv/versions/3.6.0/lib/python3.6/posixpath.py'

Or just look the module name up in sys.modules, if we know (as
we do here) that the module has already been imported.

-- 
Greg



More information about the Python-list mailing list