Skip to content

Instantly share code, notes, and snippets.

@shakna-israel
Created June 6, 2015 00:59
Show Gist options
  • Save shakna-israel/68fa53e5c7487736c8e0 to your computer and use it in GitHub Desktop.
Save shakna-israel/68fa53e5c7487736c8e0 to your computer and use it in GitHub Desktop.
For Docbuilder
filePointer = open('catchme.py', 'r')
builtFunc = []
for lines in filePointer:
if lines[:3] == 'def':
inFunc = True
if inFunc == True:
if lines[0] == lines.strip():
inFunc = False
builtFunc.append(lines.strip())
filePointer.close()
print(builtFunc)
for item in builtFunc:
if '=' in item:
exec(item)
if 'print' in item:
print("Print called on " + item)
exec(item)
strippedItem = item.strip()
if strippedItem[:5] == 'print':
pass
else:
assert False
if 'print(' in strippedItem:
strippedItem = strippedItem[6:-1]
else:
strippedItem = strippedItem[5:-1]
fileOut = open('outFile', 'w+')
fileOut.write('Output:\n```\n' + eval(strippedItem) + '\n```\n')
fileOut.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment