pycode:
#!/usr/bin/python
import os, sys
numargs = len(sys.argv)
if numargs == 1 or numargs > 2:
print """Usage: %s modulename""" % sys.argv[0]
sys.exit()
from twisted.python import reflect
obj = reflect.namedAny(sys.argv[1])
fileName = obj.__file__
if fileName[-1] == 'c':
fileName = fileName[:-1]
os.system("open %s" % fileName)
This takes advantage of the twisted utility function 'namedAny' which takes a dotted name and returns a package, module, class, function or method. This is useful for doing things like:
./openit.py urllib2
When you just want to take a quick look at the source of a module without tediously figuring out where it is located.
This will only work on OS X, which has the "open" command, but could be changed to use the EDITOR environment variable instead.
|