Subclassed dict as globals

E

Evan Simpson

In Python 2.4 the following works:
.... def __getitem__(self, k):
.... return 'K' + k
....
....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 working in
future versions of Python? For that matter, is there a way to do this
(intercept global variable accesses) in Python 2.3?

Cheers,

Evan @ 4-am
 
L

Lenard Lindstrom

Evan Simpson said:
In Python 2.4 the following works:
... def __getitem__(self, k):
... return 'K' + k
...[snip]
[Is] there a way to do this (intercept global variable accesses)
in Python 2.3?

One can emulate it in a rather limited way in pre 2.4 releases:
glbs[id] = 'K' + id

Kx Ky Kz

Special names can be used only as constants. It is better suited
for eval() than exec.

Lenard Lindstrom
<[email protected]>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top