Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Created April 3, 2013 17:42
Show Gist options
  • Save vbmendes/5303446 to your computer and use it in GitHub Desktop.
Save vbmendes/5303446 to your computer and use it in GitHub Desktop.
Script to open source code of python modules in sublime. Useful to see your dependencies source code.
#!/usr/bin/env python
# coding: utf8
import imp
import sys, os
module_name = sys.argv[1]
bits = module_name.split('.')
name = imp.find_module(bits[0])[1]
if len(bits) > 1:
subname = os.path.join(*bits[1:])
dir_path = os.path.join(name, subname)
else:
dir_path = name
if os.path.exists(dir_path):
final_path = dir_path
else:
py_path = dir_path + '.py'
if os.path.exists(py_path):
final_path = py_path
else:
print u'Module not found:\n%s\n%s\n' % (dir_path, py_path)
final_path = None
if final_path:
cmd = "subl %s" % final_path
os.system(cmd)
@vbmendes
Copy link
Author

vbmendes commented Apr 3, 2013

If you dont have subl command in osx, follow this documentation:

http://www.sublimetext.com/docs/2/osx_command_line.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment