It looks like you are not examining a module, but rather a type
object. You might try:
os.path.dirname(MODULE.__module__.__file__)
caveat
Usually you can use the __file__
attribute to find out where the module is located, but as stated in the docs (you have to scroll down a bit or ctrl + f and search for __file__
) this attribute is not present.
The __file__
attribute is not present for C modules that are statically linked into the interpreter; for extension modules loaded dynamically from a shared library, it is the pathname of the shared library file.
You can however use the imp
module. It has the find_module function which will perform the same search that is performed when you actually import the module. This would lead to code like this:
import imp
data = imp.find_module("MODULE")
# The path of the module is the second element of the tuple
pathname = data[1]