[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)

Eric Snow ericsnowcurrently at gmail.com
Tue Nov 26 00:51:36 CET 2013


On Mon, Nov 25, 2013 at 4:37 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 11/25/2013 5:31 PM, Eric Snow wrote:
>>
>> On Mon, Nov 25, 2013 at 3:14 PM, Antoine Pitrou <solipsis at pitrou.net>
>> wrote:
>>>
>>> (I also understand that it relies on a more-or-less implementation
>>> detail, but the implementation detail will have to stay for
>>> compatibility reasons, anyway)
>>
>>
>> What implementation detail are you talking about?
>
>
> The fact that .__name__ is set to "__main__" in the main module.

I don't see why that's an implementation detail.  The language
reference specifies that scripts are run in the namespace of the main
module and that it's named "__main__". [1][2]

-eric

[1] http://docs.python.org/3.4/reference/executionmodel.html#naming-and-binding
[2] http://docs.python.org/3.4/reference/toplevel_components.html#complete-python-programs


More information about the Python-ideas mailing list