Created
June 11, 2013 19:48
-
-
Save newgiin/5759997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import re | |
import shutil | |
f = open(sys.argv[1], 'r') | |
buf_file = open('probs/temp.py', 'w') | |
prob_pat = re.compile('^def (e_[0-9]+)\(\):') | |
e_name = '' | |
in_e = False | |
for line in f: | |
if in_e and line[0:3] == 'def': | |
buf_file.write("if __name__ == '__main__':\n") | |
buf_file.write(" main()\n") | |
buf_file.close() | |
shutil.copyfile('probs/temp.py', | |
'probs/' + e_name + '.py') | |
buf_file = open('probs/temp.py', 'w') | |
in_e = False | |
mr = prob_pat.match(line) | |
if mr: | |
e_name = mr.group(1) | |
in_e = True | |
buf_file.write("def main():\n") | |
else: | |
buf_file.write(line) | |
if in_e: | |
buf_file.write("if __name__ == '__main__':\n") | |
buf_file.write(" main()\n") | |
buf_file.close() | |
shutil.copyfile('probs/temp.py', | |
'probs/' + e_name + '.py') | |
else: | |
buf_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment