out = open('nesting.py', 'w') out.write(""" import sys def func0(): try: return func0() except RuntimeError: return sys.exc_info() """) x = 0 for x in range(1, 100): out.write(""" def func%i(): try: return func%i() except RuntimeError: return func%i() """ % (x,x,x-1)) out.close() from nesting import * func1() func5() func15() func20() func30()