>> d = {} >> exec source_code in d >> some_name = d['some_name'] > > This works quite well! I can't believe after googling for half on hour I > didn't notice this "exec ... in ..." syntax. > One more thing though, is there a way to access "some_name" as a > attribute, instead as a dictionary: > > some_name = d.some_name
Sure: class D:pass d = D() exec source_code in d.__dict__ print d.some_name Notice that this will also give you d.__builtins__, which you might want to del afterwards. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list