Why all the __double_underscored_vars__?

Yongjian Xu jimxu at google.com
Sat Aug 8 12:47:14 EDT 2009


These "special" methods are not meant to be used or known to beginners. They
aren't even meant to be called directly (in most cases). They are either
operator overloading methods or behavior customization methods. In my
opinion, in the meta programming realm. Should probably in advanced topic or
something.


On Sat, Aug 8, 2009 at 5:11 AM, kj <no.email at please.post> wrote:

> In <mailman.4446.1249683227.8015.python-list at python.org> Chris Rebert <
> clp2 at rebertia.com> writes:
>
> >The double-underscores indicate that the Python interpreter itself
> >usually is the caller of the method, and as such some level of "magic"
> >may be associated with it. Other languages have you do the equivalent
> >of `def +():` or `def operator +()` to override an operator, the
> >keyword or symbol serving a similar warning that "here be magic".
>
> In this case, then I hope that some of these __items__ get demoted
> to a more mundane level, so that the notion of "magic" doesn't get
> trivialized by everyday idioms like:
>
> if __name__ == '__main__':
>    # etc
>
> There are a few in this category...  I figure that they are cases
> of "atavistic magic".
>
> I bring this up because I find it quite difficult to explain to my
> students (who are complete newcomers to programming) all the
> __underscored__ stuff that even rank noobs like them have to deal
> with.  (Trust me, to most of them your reply to my post would be
> as clear as mud.)  This suggests to me that there's something a
> bit unnatural about some of these __items__.
>
> Anyway, thanks for your post.  I see your point.
>
> kynn
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090808/4015e00f/attachment.html>


More information about the Python-list mailing list