Quick question: forcing exec() within a specific namespace
Ken Kinder
ken at _nospam_ken.x13.com
Wed May 26 00:49:42 EDT 1999
Sarino Suon wrote:
>
> In the interactive interpreter, when I call exec(), whatever objects are
> created belong to the __main__ module. What if I need the objects to be
> attached to a specific object, such as a class instance? Can this be done?
>
> --- Sarino
Yeah, it can. Here's how it works: exec(code, [, globals [, locals ] ])
Globals and locals are namespaces, in dictionary form. By default, the
name space of the calling code is used.
More information about the Python-list
mailing list