Skip to content

Instantly share code, notes, and snippets.

@iandanforth
Created June 28, 2013 21:35
Show Gist options
  • Save iandanforth/5888328 to your computer and use it in GitHub Desktop.
Save iandanforth/5888328 to your computer and use it in GitHub Desktop.
#! /usr/bin/python
import os
import subprocess
import time
iteration = 1
def main():
if iteration >= 20:
quit()
filename = "replicator%d.py" % iteration
nextFilename = "replicator%d.py" % (iteration + 1)
with open(filename, 'r') as fh:
with open(nextFilename, 'w') as ofh:
for line in fh:
if 'iteration' in line:
oldString = "iteration = %d" % iteration
newString = "iteration = %d" % (iteration + 1)
newline = line.replace(oldString, newString)
if newline != line:
line = newline
print line.strip('\n')
ofh.write(line)
cmd = "python %s" % nextFilename
time.sleep(.5)
subprocess.call(cmd, shell=True)
print "Done, back in interation %d" % iteration
time.sleep(.5)
# Kill the offspring!!!
if iteration == 1:
for i in range(2, 21):
rmname = "replicator%d.py" % i
os.remove(rmname)
# Now do it all over again!
subprocess.call('python replicator1.py', shell=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment