개발/Python

Python module path directory find

강서버 2021. 4. 27. 15:23
728x90
반응형

1. (module_name).__file__

ex,

>>> import pandas

>>> pandas.__file__

'/home/user/.local/lib/python3.8/site-packages/pandas/__init__.py'

 

2. os.path.abspath()

ex,

>>> import os

>>> os.path.abspath(pandas.__file__)

'/home/user/.local/lib/python3.8/site-packages/pandas/__init__.py'

 

* module directory

>>> os.path.dirname(pandas.__file__)

'/home/user/.local/lib/python3.8/site-packages/pandas'

 

3. inspect module

ex,

>>> import inspect

>>> inspect.getfile(pandas)

'/home/user/.local/lib/python3.8/site-packages/pandas/__init__.py'

 

728x90
반응형