modulename.__file__
tells you the path where the module (.pyc) is loaded.
import a_module
print a_module.__file__
#or
import os
path = os.path.abspath(amodule.__file__)
If you want to know that the directory of the module has changed, you can write as follows.
import os
path = os.path.dirname(amodule.__file__)
inspection provides information on Representatively,
Examples include member variables/functions in class, parameter format of functions, source code of methods, and so on. p>module
or class
, methods
, functions
, tracacks
, and
p>
import os
import inspect
print(inspect.getfile(os)) #'/usr/lib64/python2.7/os.pyc'
print(inspect.getfile(inspect)) #'/usr/lib64/python2.7/inspect.pyc'
os.path.dirname(inspect.getfile(inspect)) #'/usr/lib64/python2.7'
© 2024 OneMinuteCode. All rights reserved.