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 module
or class
, methods
, functions
, tracacks
, and
Representatively,
Examples include member variables/functions in class, parameter format of functions, source code of methods, and so on.
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'
2022-09-21 21:12
If you have any answers or tips
Popular Tags
python x 4647
android x 1593
java x 1494
javascript x 1427
c x 927
c++ x 878
ruby-on-rails x 696
php x 692
python3 x 685
html x 656
© 2025 OneMinuteCode. All rights reserved.