Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a python equivalent to the Unix `which` command?

Tags:

python

I'd like to know where the module I'm about to import is coming from. Is there a which command in python?

Example:

>>> which module_name
/usr/lib/python2.6/site-packages/module_name.py
like image 909
Conley Owens Avatar asked Jun 22 '10 02:06

Conley Owens


1 Answers

import imp
imp.find_module(module_name)

Help on built-in function find_module
in module imp:

find_module(...)
find_module(name, [path]) -> (file, filename, (suffix, mode, type))
Search for a module. If path is omitted or None, search for a built-in, frozen or special module and continue search in sys.path. The module name cannot contain '.'; to search for a submodule of a package, pass the submodule name and the package's __path__.

like image 153
John La Rooy Avatar answered Nov 06 '22 23:11

John La Rooy