changing local namespace of a function
Alex Martelli
aleaxit at yahoo.com
Sat Feb 5 04:37:11 EST 2005
Bo Peng <bpeng at rice.edu> wrote:
...
> Thank again for everyone's help. I have learned a lot from the posts,
> especially the wrapdict class.
Hmmm, you do realize that wrapdict uses a lot of indirection while my
equivalent approach, just posted, is very direct, right? To reiterate
the latter, and dress it up nicely too, it's
class wrapwell(object):
def __init__(self, somedict):
self.__dict__ = somedict
and use d=wrapwell(whateverdict) to make the wrapper. Now, reading or
writing d.x is just like reading or writing whateverdict['x'], etc etc.
Alex
More information about the Python-list
mailing list