Skip to content

Instantly share code, notes, and snippets.

@akaptur
Created September 29, 2014 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akaptur/2accd2dbe8bacb93de40 to your computer and use it in GitHub Desktop.
Save akaptur/2accd2dbe8bacb93de40 to your computer and use it in GitHub Desktop.
def write_chained_functions(total_functions):
with open('/usr/share/dict/words','r') as name_file:
fn_names = [line.strip() for line in name_file.readlines()]
first_name = fn_names[0]
last_name = fn_names[total_functions]
fn_names = iter(fn_names)
with open("empty_chain.py", 'w') as f:
name = next(fn_names)
following_name = next(fn_names)
for _ in range(total_functions):
f.write("def %s():\n" % name)
f.write(" %s()\n\n" % following_name)
name, following_name = following_name, next(fn_names)
f.write("def %s():\n print 'yay'\n" % last_name)
f.write("%s()" % first_name)
if __name__ == '__main__':
write_chained_functions(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment