Finding the name of an object's source file
Matt Wheeler
m at funkyhat.org
Tue Jun 6 09:52:55 EDT 2017
On Tue, 6 Jun 2017 at 11:20 Peter Otten <__peter__ at web.de> wrote:
>
> >>> import os
> >>> inspect.getsourcefile(os.path.split)
> '/usr/lib/python3.4/posixpath.py'
>
> And so much more fun than scanning the documentation :)
>
Alternatively, without using inspect, we can get around `Object.__module__`
being a string by importing it as a string:
>>> import importlib, os
>>> importlib.import_module(os.path.split.__module__).__file__
'/Users/matt/.pyenv/versions/3.6.0/lib/python3.6/posixpath.py'
--
--
Matt Wheeler
http://funkyh.at
More information about the Python-list
mailing list