dictionary and __getattr__

Daniel Dittmar daniel.dittmar at sap.com
Thu Sep 6 07:29:49 EDT 2001


> 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.

class AttributeDict (UserDict):
    __getattr__ = UserDict.__getitem__

Daniel






More information about the Python-list mailing list