Returning a value from exec or a better solution

Ian Kelly ian.g.kelly at gmail.com
Wed Aug 31 16:25:43 CEST 2011


On Wed, Aug 31, 2011 at 12:35 AM, Arnaud Delobelle <arnodel at gmail.com> wrote:
>> You don't know that, an implementation may for example set __bultins__
>> to None, prior to returning, its not an unreasonable thing to do and
>> the docs don't say they can't.
>
> I haven't studied the docs but I'm certain that such an implementation
> would break a lot of code.

For example:

a = 42
exec "a += 1729"
print(a)

...since print would no longer be available in the global namespace.

Cheers,
Ian



More information about the Python-list mailing list