Re: Subclassed dict as globals

2005-01-26 Thread Lenard Lindstrom
Evan Simpson <[EMAIL PROTECTED]> writes: > In Python 2.4 the following works: > > >>> class G(dict): > ... def __getitem__(self, k): > ... return 'K' + k > ... > >>> g = G() > >>> exec 'print x, y, z' in g > Kx Ky Kz > >>> > [snip] > [Is] there a way to do this (intercept global variable

Re: Subclassed dict as globals

2005-01-26 Thread Terry Reedy
"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Evan Simpson wrote: > >> In Python 2.4 the following works: >> >> >>> class G(dict): >> ... def __getitem__(self, k): >> ... return 'K' + k >> ... >> >>> g = G() >> >>> exec 'print x, y, z' in g >> Kx Ky Kz >> >>>

Re: Subclassed dict as globals

2005-01-26 Thread Fredrik Lundh
Evan Simpson wrote: > In Python 2.4 the following works: > > >>> class G(dict): > ... def __getitem__(self, k): > ... return 'K' + k > ... > >>> g = G() > >>> exec 'print x, y, z' in g > Kx Ky Kz > >>> > > ...while in Python 2.3 it fails with NameError: name 'x' is not defined. Is > this an

Subclassed dict as globals

2005-01-26 Thread Evan Simpson
In Python 2.4 the following works: >>> class G(dict): ... def __getitem__(self, k): ... return 'K' + k ... >>> g = G() >>> exec 'print x, y, z' in g Kx Ky Kz >>> ...while in Python 2.3 it fails with NameError: name 'x' is not defined. Is this an "accidental feature", or can I count on this