The meaning of "="
Aahz
aahz at pythoncraft.com
Wed Jul 15 09:05:30 EDT 2009
In article <m2vdluxt0j.fsf at cs.uu.nl>, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>> aahz at pythoncraft.com (Aahz) (A) wrote:
>
>>A> In article <m27hybyo95.fsf at cs.uu.nl>, Piet van Oostrum <piet at cs.uu.nl> wrote:
>>>>>>>>> aahz at pythoncraft.com (Aahz) (A) wrote:
>>>>
>>A> In article <m24otg3hkk.fsf at cs.uu.nl>, Piet van Oostrum
>>A> <piet at cs.uu.nl> 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).
>
>>A> c.x = 4
>>A> already updates the instance dict, so there's no need to change any class
>>A> methods to support it. That is, IME it's much better to add methods to
>>A> a regular class to make it more dict-like using the built-in instance
>>A> dict rather than changing any of the attribute mechanisms. If you're
>>A> really curious, I recommend trying several approaches yourself to see
>>A> what works better. ;-)
>
>Yes, that's why I mentioned __setitem__. I just mixed up the motivation.
Gotcha. Unfortunately, I can only respond to what you've written, not
what you intended to write. ;-) (There was enough misinformation
earlier in this thread that I felt being really really clear was
important.)
--
Aahz (aahz at pythoncraft.com) <*> 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
More information about the Python-list
mailing list