Skip to content

Instantly share code, notes, and snippets.

@donghee
Created April 21, 2011 15:56
Show Gist options
  • Save donghee/934828 to your computer and use it in GitHub Desktop.
Save donghee/934828 to your computer and use it in GitHub Desktop.
Signature Survey in python
#!/usr/bin/python
# Signature Survey Python version
# http://c2.com/doc/SignatureSurvey/
# 2011, Donghee Park
import sys
import re
re_def = re.compile("def (.*):$")
re_class = re.compile("^class (.*):$")
for line in sys.stdin:
if (r'"""' in line.strip()[0:3]) or ('\n' == line):
continue
if 'import ' in line:
sys.stdout.write('i')
continue
if ' def ' in line:
sys.stdout.write('\n')
sys.stdout.write(' ')
sys.stdout.write(re_def.findall(line)[0])
continue
if 'class ' in line:
sys.stdout.write('\n')
sys.stdout.write(re_class.findall(line)[0])
continue
if 'def ' in line:
sys.stdout.write('\n')
sys.stdout.write(re_def.findall(line)[0])
continue
if ':\n' in line:
sys.stdout.write(':')
continue
if not '#' in line:
sys.stdout.write(';')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment