Im sure there is a simple way to get a modules path from the modulename, right? I.e. I want to retrieve /path/to/module from path.to.module preferably in python 2.7.
I dont intend to import the module and I have the modulename as a string.
This is fairly easy after importing a module:
import os
print os.__file__
prints
/usr/lib/python2.7/os.pyc
on my machine.
To do this before importing a module, you can use imp.find_module()
:
imp.find_module("os")[1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With