git.fiddlerwoaroof.com
splitsnippets.py
1096adbe
 """
 Split a file of python snippets into its constituent snippets, splitting
 on lines whose first non-whitespace character is #
 """
c4ec28c6
 import sys
 counter = 0
 with open(sys.argv[1]) as f:
 	buffer = []
 	for line in f:
4e75ae60
 		lline = line.strip()
9c112cd3
 		line = line.rstrip()
4e75ae60
 		if set(lline) != set(['#']):
c4ec28c6
 			buffer.append(line)
 		else:
 			with file('%s_%04d.py' %(f.name.rpartition('.')[0], counter), 'w') as g:
 				g.write('\n'.join(buffer))
 				buffer = []
 				counter += 1