Bruno Desthuilliers a écrit : > Martin Drautzburg a écrit : > >> This may be pretty obvious for most of you: >> >> When I have an object (an instance of a class "Foo") I can access >> attributes via dot notation: >> >> aFoo.bar >> >> however when I have a dictionary >> aDict = {"bar":"something"} >> >> I have to write >> >> aDict["bar"] >> >> What if I want to create a datastructure that can be used in dot >> notation without having to create a class, i.e. because those objects >> have no behavior at all? > > > A class inheriting from dict and implementing __getattr__ and > __setattr__ should do the trick...
Oh, yes, if you don't care about dict-like behaviour, you can also just: class Data(object): def __init__(self, **kw): self.__dict__.update(kw) -- http://mail.python.org/mailman/listinfo/python-list