Quick question: forcing exec() within a specific namespace

Just van Rossum just at letterror.com
Thu May 20 13:34:35 EDT 1999


Sarino Suon wrote:
>In the interactive interpreter, when I call exec(), [ ... ]

Michael P. Reilly wrote:
>  >>> exec('a = 10', private, private)

Guys, exec is a *statement*, not a function. Better spell it without the
parens, using the "in" keyword:

>>> exec "a = 10" in private, private
>>>

That the above still works is mainly for backwards compatibility, back when
exec indeed was a function (but that's way before my time ;-).

Just






More information about the Python-list mailing list