[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
This commit is contained in:
hpk 2008-07-02 10:42:24 +02:00
parent 671f6a4660
commit 15b129a12e
1 changed files with 23 additions and 0 deletions

23
py/bin/py.which Executable file
View File

@ -0,0 +1,23 @@
#!/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