git.fiddlerwoaroof.com
Raw Blame History
#!/usr/bin/env python -O
"""
Edit a python file by its module name (i.e. twisted.internet.thread)
I usually alias this to some one character symbol like ,
"""

import os
import os.path
import sys
import imp

EDITOR='/usr/local/bin/vim'
append = []
sys.path.append('.')

module = sys.argv[1].split('.')
module[0] = imp.find_module(module[0])[1]
try:
	filename = reduce(lambda a,b: imp.find_module(b, [a])[1], module)
except ImportError:
	filename = reduce(lambda a,b: imp.find_module(b, [a])[1], module[:-1])
	definition = module[-1]
	append.extend(['+/\\c\(\(def\)\|\(class\)\) %s' % definition])

append.extend([filename])
os.execl(EDITOR, os.path.basename(EDITOR), *append)