dictionary and __getattr__
Michael Abbott
michael at rcp.co.uk
Thu Sep 6 06:24:44 EDT 2001
More information about the Python-list mailing list
Thu Sep 6 06:24:44 EDT 2001
- Previous message (by thread): dictionary and __getattr__
- Next message (by thread): dictionary and __getattr__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Harald Kirsch <kirschh at lionbioscience.com> wrote in news:yv28zfsr6e8.fsf at lionsp093.lion-ag.de: > > > Wouldn't it be nice if this would work: > > d = {'x': 1} > print d.x > > i.e. every entry in a dictionary is also an attribute of the > dictionary itself. > > Is there a class wrapper for that somewhere available? I expect this would work: class Wrap: def __init__(self, dict): self.__dict__.update(dict) d = {'x': 1} dd = Wrap(d) print dd.x Of course, this may not be exactly what you want, because dd won't follow updates to d.
- Previous message (by thread): dictionary and __getattr__
- Next message (by thread): dictionary and __getattr__
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list