Advanced Dictionary

Stephen Hansen me+list/python at ixokai.io
Wed Jun 16 12:17:47 EDT 2010


On 6/16/10 6:10 AM, Peter Otten wrote:
> Thomas Lehmann wrote:
> 
>>> class AutoValueDict(dict):
>>>     def __makeitem__(self, key):
>>>         return self.setdefault(key, {})
> 
> I think it's bad style to invent your own __whatever__() methods, I'd rather 
> call them _whatever().

It goes a bit beyond bad style into, "it is explicitly forbidden", I think.

Not that "forbidden" means, "Python will prevent you from trying", just
that it says, "Don't do it."

Leading-and-trailing double underscores are explicitly reserved for
Python to define as Special. They also imply a slightly different
calling semantic: normal leading-and-trailing double underscore methods
bypass instance lookup.

-- 

   Stephen Hansen
   ... Also: Ixokai
   ... Mail: me+list/python (AT) ixokai (DOT) io
   ... Blog: http://meh.ixokai.io/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20100616/5f689ef5/attachment-0001.sig>


More information about the Python-list mailing list