From 1db53edee7620623427271597e9393842a5b3a5d Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Tue, 27 Jan 2015 12:15:09 -0800 Subject: [PATCH] Add pywhich script --- home/bin/pywhich | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 home/bin/pywhich diff --git a/home/bin/pywhich b/home/bin/pywhich new file mode 100755 index 0000000..5dcaed5 --- /dev/null +++ b/home/bin/pywhich @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +# pywhich - Find out where a Python module lives. +# +# Works like `which` but for Python modules. +# Usage: pywhich some.module.name +# +# --Kirsle +# http://sh.kirsle.net/ + +from __future__ import print_function +from sys import argv, exit +from importlib import import_module + +if len(argv) == 1: + print("Usage: {} ".format(argv[0])) + exit(1) + +for module in argv[1:]: + try: + mod = import_module(module) + print("{}: {}".format(module, mod.__file__)) + except ImportError: + print("{}: not found".format(module))