[py-svn] r56231 - py/trunk/py/bin

hpk at codespeak.net hpk at codespeak.net
Wed Jul 2 10:42:26 CEST 2008


Author: hpk
Date: Wed Jul  2 10:42:24 2008
New Revision: 56231

Added:
   py/trunk/py/bin/py.which   (contents, props changed)
Log:
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.


Added: py/trunk/py/bin/py.which
==============================================================================
--- (empty file)
+++ py/trunk/py/bin/py.which	Wed Jul  2 10:42:24 2008
@@ -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



More information about the pytest-commit mailing list