Files
pytest2/py/bin/py.which
hpk 15b129a12e [svn r56231] add a small script that tells where an import of a python module package would come from.
py.which is meant to be the equivalent of "which" in unix.

--HG--
branch : trunk
2008-07-02 10:42:24 +02:00

24 lines
492 B
Python
Executable File

#!/usr/bin/env python
"""\
py.which [name]
print the location of the given python module or package name
"""
import sys
if __name__ == '__main__':
name = sys.argv[1]
try:
mod = __import__(name)
except ImportError:
print >>sys.stderr, "could not import:", name
else:
try:
location = mod.__file__
except AttributeError:
print >>sys.stderr, "module (has no __file__):", mod
else:
print location