I want to find out where the module is in path

Asked 2 years ago, Updated 2 years ago, 150 views

I want to find out if the module has been modified or changed. I know how to find out the last revision date How do I find out where the module is located?

python module inotify

2022-09-21 21:12

1 Answers

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


© 2024 OneMinuteCode. All rights reserved.