On Thu, Jun 5, 2008 at 5:40 AM, Gabriel Rossetti <<a href="mailto:gabriel.rossetti@arimaz.com">gabriel.rossetti@arimaz.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hello everyone,<br>
<br>
I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static) attributes. I had done this and it seamed to work, until I subclassed a class using this technique and from there on things started screwing up. I finally tracked it down to self.__class__.attribute! What was happening is that the child classes each over-rode the class attribute at their level, and the parent's was never set, so while I was thinking that I had indeed a class attribute set in the parent, it was the child's that was set, and every child had it's own instance! Since it was a locking mechanism, lots of fun to debug... So, I suggest never using self.__class__.attribute, unless you don't mind it's children overriding it, but if you want a truly top-level class attribute, use ClassName.attribute everywhere!<br>
<br>
I wish books and tutorials mentioned this explicitly....<br>
<br>
Gabriel<br><font color="#888888">
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>Thanks for the info. Can anyone explain more about the differences between the two techniques? Why does one work and the other one fail?<br>Casey<br>