From 15b129a12e71d20e1e9726b265ebd9e266b34ea5 Mon Sep 17 00:00:00 2001 From: hpk Date: Wed, 2 Jul 2008 10:42:24 +0200 Subject: [PATCH] [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 --- py/bin/py.which | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 py/bin/py.which diff --git a/py/bin/py.which b/py/bin/py.which new file mode 100755 index 000000000..6e54abd4a --- /dev/null +++ b/py/bin/py.which @@ -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