Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.249.MISMATCH!transit3.readnews.com!news-out.readnews.com!transit4.readnews.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: Python Newbie Date: Sun, 24 Feb 2013 11:22:36 -0500 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 37 Message-ID: References: <5127848B.1060004@gmail.com> <928d2cf7-728b-4f35-b8c9-4c9b958507e5@googlegroups.com> <8eadd52c-d533-4333-8c7f-7bf3a6d7b046@googlegroups.com> <9p1ii899tkalvfd1cl7sneoqa9t1cqh4oj@invalid.netcom.com> <5129482F.3080402@gmail.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1361722957 17331 127.0.0.1 (24 Feb 2013 16:22:37 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 24 Feb 2013 16:22:37 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) X-Received-Bytes: 2727 Xref: csiph.com comp.lang.python:39753 In article , Chris Angelico wrote: > The "dunder" methods ("d"ouble "under"score, leading and trailing), > also called "magic methods", are the implementations of various > special features. For instance, indexing foo[1] is implemented using > the __getitem__ method. Here's a list: > > http://docs.python.org/3.3/reference/datamodel.html#special-method-names > > You'll seldom, if ever, call these methods directly. On the other hand, once you get into building your own classes, you will often be *writing* them. The most common are __str__(), __repr__(), and __unicode__(), and of course, __init__(). A quick look over my current project shows 471 classes, and I've defined: 1 __del__ 1 __getattr__ 1 __iter__ 1 __new__ 2 __cmp__ 2 __len__ 3 __ne__ 4 __contains__ 9 __eq__ 14 __str__ 38 __unicode__ 62 __repr__ 140 __init__ Not to mention the boilerplate: if __name__ == '__main__": which shows up all over the place.