Conley Owens
Conley Owens

Reputation: 9163

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

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

Upvotes: 6

Views: 592

Answers (1)

John La Rooy
John La Rooy

Reputation: 304147

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__.

Upvotes: 8

Related Questions