def main(): s = \ """ y = 3 def execfunc(): print y execfunc() """ d = {} e = {} exec s in d, e if __name__ == '__main__': main()