Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get path from a module name

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.

like image 946
joidegn Avatar asked Dec 04 '22 04:12

joidegn


1 Answers

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]
like image 97
Sven Marnach Avatar answered Jan 01 '23 23:01

Sven Marnach