Why all the __double_underscored_vars__?

kj no.email at please.post
Sat Aug 8 14:49:28 EDT 2009


In <mailman.4455.1249736560.8015.python-list at python.org> David Cournapeau <cournape at gmail.com> writes:

>On Sat, Aug 8, 2009 at 9:11 PM, kj<no.email at please.post> wrote:
>> In <mailman.4446.1249683227.8015.python-list at python.org> Chris Rebert <cl=
>p2 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__ =3D=3D '__main__':
>> =C2=A0 =C2=A0# etc
>>
>> There are a few in this category... =C2=A0I 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. =C2=A0(Trust me, to most of them your reply to my post would be
>> as clear as mud.)

>Maybe your students do not need to know about it, at least at the
>beginning ? I heavily use python, and do not use the underscore
>methods so much most of the time, except for __init__,

Believe me, it's not me who's bringing this stuff up: *they*
specifically ask.  That's precisely my point: it is *they* who
somehow feel they can't avoid finding out about this stuff; they
must run into such __arcana__ often enough to cause them to wonder.
If at least some rank beginners (i.e. some of my students) feel
this way, I suggest that some of this alleged __arcana__ should be
demoted to a more mundane everyday status, without the scare-underscores.
E.g. maybe there should be a built-in is_main(), or some such, so
that beginners don't have to venture into the dark underworld of
__name__ and "__main__".

kynn



More information about the Python-list mailing list