3 Suggestions to Make Python Easier For Children
Marko Rauhamaa
marko at pacujo.net
Tue Aug 5 08:04:27 EDT 2014
Brian Blais <bblais at gmail.com>:
> class Struct(dict):
>
> def __getattr__(self,name):
>
> try:
> val=self[name]
> except KeyError:
> val=super(Struct,self).__getattribute__(name)
>
> return val
>
> def __setattr__(self,name,val):
>
> self[name]=val
Cool. I wonder if that should be built into dict.
Why can't I have:
>>> d = {}
>>> d.x = 3
>>> d
{'x': 3}
Marko
More information about the Python-list
mailing list