Why all the __double_underscored_vars__?
Steven D'Aprano
steve at REMOVE-THIS-cybersource.com.au
Sun Aug 9 04:48:16 EDT 2009
On Sat, 08 Aug 2009 12:11:19 +0000, kj 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
But that is magic, and just because it's magic doesn't mean it's not
useful every day.
I don't see what's so difficult about telling your students that double
underscore names have special meaning to the Python interpreter. That
doesn't mean you're forbidden from using them, or that you have to use
them, it just means that they have a special meaning to the interpreter,
and you usually don't call them directly.
--
Steven
More information about the Python-list
mailing list