User defined lexical scoping... can I do this?

Terry Reedy tjreedy at udel.edu
Tue Sep 18 21:38:19 EDT 2012


On 9/18/2012 5:51 PM, Thomas Jollans wrote:
> On 09/18/2012 10:50 PM, weissman.mark at gmail.com wrote:
>> Well there's wired stuff like this:
>>
>> In [1]: locals()["x"] = 5
>>
>> In [2]: print x
>> 5
>>
>
> No, there isn't. Modifying the dictionary returned by locals() has no
> effect.

Last time I tried it, it does within a class -- in cpython at least. 
That locals dict usually becomes the __dict__ of the class. But not to 
be depended on indefinitely and across implmentations.


-- 
Terry Jan Reedy




More information about the Python-list mailing list