Apr-16-2019, 06:30 PM
You can type just the imported module name into the console.
You get back the representation of the object. This works with all objects.
In addition you can import inspect and get the sourcefile of a loaded module.
Here some examples:
You get back the representation of the object. This works with all objects.
In addition you can import inspect and get the sourcefile of a loaded module.
Here some examples:
In [1]: import datetime In [2]: import time In [3]: datetime Out[3]: <module 'datetime' from '/home/deadeye/.pyenv/versions/3.7.3/lib/python3.7/datetime.py'> In [4]: time Out[4]: <module 'time' (built-in)> In [5]: from datetime import time, date, timedelta, timezone In [6]: time, date, timedelta, timezone Out[6]: (datetime.time, datetime.date, datetime.timedelta, datetime.timezone) In [7]: time Out[7]: datetime.time In [8]: import time In [9]: time Out[9]: <module 'time' (built-in)> In [10]: import inspect In [11]: inspect.getsourcefile(time) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-11-69e21971e6e5> in <module> ----> 1 inspect.getsourcefile(time) ~/.pyenv/versions/3.7.3/lib/python3.7/inspect.py in getsourcefile(object) 682 Return None if no way can be identified to get the source. 683 """ --> 684 filename = getfile(object) 685 all_bytecode_suffixes = importlib.machinery.DEBUG_BYTECODE_SUFFIXES[:] 686 all_bytecode_suffixes += importlib.machinery.OPTIMIZED_BYTECODE_SUFFIXES[:] ~/.pyenv/versions/3.7.3/lib/python3.7/inspect.py in getfile(object) 645 if getattr(object, '__file__', None): 646 return object.__file__ --> 647 raise TypeError('{!r} is a built-in module'.format(object)) 648 if isclass(object): 649 if hasattr(object, '__module__'): TypeError: <module 'time' (built-in)> is a built-in module In [12]: inspect.getsourcefile(datetime) Out[12]: '/home/deadeye/.pyenv/versions/3.7.3/lib/python3.7/datetime.py' In [13]: from datetime import time, date, timedelta, timezone In [14]: inspect.getsourcefile(time) Out[14]: '/home/deadeye/.pyenv/versions/3.7.3/lib/python3.7/datetime.py' In [15]:
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!
Reply