help on eval()-like but return module object

"Martin v. Löwis" martin at v.loewis.de
Thu Jan 12 18:57:11 EST 2006


Dody Suria Wijaya wrote:
> Any helps on this topic would be highly appreciated. Thanks!

You can use new.module to create a new module, and exec to
execute some code in the module:

py> m = new.module("Hallo")
py> exec "a=3" in m.__dict__
py> m.a
3
py> m
<module 'Hallo' (built-in)>

Regards,
Martin



More information about the Python-list mailing list