1#!/usr/bin/env python
2
3"""\
4py.which [name]
5
6print the location of the given python module or package name
7"""
8
9import sys
10
11def main():
12    name = sys.argv[1]
13    try:
14        mod = __import__(name)
15    except ImportError:
16        sys.stderr.write("could not import: " +  name + "\n")
17    else:
18        try:
19            location = mod.__file__
20        except AttributeError:
21            sys.stderr.write("module (has no __file__): " + str(mod))
22        else:
23            print(location)
24