In article <[email protected]>, Piet van Oostrum <[email protected]> wrote: >>>>>> [email protected] (Aahz) (A) wrote: > >>A> In article <[email protected]>, Piet van Oostrum >>A> <[email protected]> wrote: > >>>> And to get c.x = 4 working you also need a __setitem__. > >>A> Nope. You do need __setitem__ so that this works: > >>A> c['x'] = 4 > >Sorry, I meant such that c.x = 4 does the same as c['x'] = 4 because >that was what the OP wanted (I think).
c.x = 4 already updates the instance dict, so there's no need to change any class methods to support it. That is, IME it's much better to add methods to a regular class to make it more dict-like using the built-in instance dict rather than changing any of the attribute mechanisms. If you're really curious, I recommend trying several approaches yourself to see what works better. ;-) -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." --Red Adair -- http://mail.python.org/mailman/listinfo/python-list
