Thanks for your response! (And sorry about the syntax error, I forgot
to test my code after cleaning up some debug statements before
posting, the else should have been elif indeed.)
It's very interesing, how Python works internally. According to a
thread on the Python mailing list in 2002, it seem
On 12/8/2010 8:01 AM, Jonathan S wrote:
class Global(dict):
def __init__(self):
pass
def __getitem__(self, key):
import __builtin__
if key == 'xx':
return 'xx'
if hasattr(__builtin__, key):
return getattr(__builtin__, key)
Shouldn't
return 'xx'
be
return self['xx'
I don't know why precisely you're using a class as a global namespace,
not that I personally find fault with it. But here are some other
things you can do.
Idea one:
==
class NS(object): """plac
Shouldn't
return 'xx'
be
return self['xx']
--
http://mail.python.org/mailman/listinfo/python-list
Couple of things:
I don't think this is what you want:
def __getitem__(self, key):
import __builtin__
if key == 'xx':
return 'xx'
I won't return a KeyError for any string you give g[]
It will return 'xx' only if you supply key='xx' and ignore every other
key=???
Wit