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

Eric Snow ericsnowcurrently at gmail.com
Fri Dec 6 17:29:25 CET 2013


On Tue, Nov 26, 2013 at 3:01 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> On 26 Nov 2013 10:00, "Mark Janssen" <dreamingforward at gmail.com> wrote:
>>
>> The only other possibility not mentioned thus far is to have a main.py
>> file and force python programs to start from it.
>
> Looking for a __main__.py module (or submodule) is the way directory,
> zipfile and package execution work, so this style is already possible
today
> for anyone that wants or needs it.

It also doesn't work so well for non-packages. :)

That said, I like how __main__.py makes a clear separation between the
package and its script form. As I said in my opening email, I think that
distinction is very fuzzy for modules in general and bites both beginners
and advanced users. For me anything that proposed replacing the current "if
__name__ == '__main__'" idiom should help make the script/module separation
more distinct.

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131206/1435822c/attachment.html>


More information about the Python-ideas mailing list