<div dir="ltr">I'm not in love with the *spelling* of " if __name__=='__main__': ", but I very frequently use the overall pattern.<div><br></div><div>Much--or even most--of the time when I write a module, I like to allow it to either do a minimal case of its basic functionality and/or have the module run some basic unit tests as a quick check against breakage.  So in contrast to Eric Snow, I try *to* make my files both scripts and modules.  I know this isn't the only possible approach, but I don't think it's bad or uncommon.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Nov 22, 2013 at 1:40 PM, Eric Snow <span dir="ltr"><<a href="mailto:ericsnowcurrently@gmail.com" target="_blank">ericsnowcurrently@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Fri, Nov 22, 2013 at 1:44 PM, Gregory P. Smith <<a href="mailto:greg@krypto.org">greg@krypto.org</a>> wrote:<br>

> It'd be nice to formalize a way to get rid of the __name__ == '__main__'<br>
> idiom as well in the long long run. Sure everyone's editor types that for<br>
> them now but it's still a wart.  Anyways, digressing... ;)<br>
<br>
This has come up before and is the subject of several PEPS. [1][2]<br>
The current idiom doesn't bother me too much as I try not to have<br>
files that are both scripts and modules.  However, Python doesn't make<br>
the distinction all that clear nor does it do much to encourage people<br>
to keep the two separate.  I'd prefer improvements in both those<br>
instead, but haven't had the time for any concrete proposal.<br>
<br>
FWIW, aside from the idiom there are other complications that arise<br>
from a module that also gets loaded in __main__ (run as a script).<br>
See PEP 395 [3].<br>
<br>
-erc<br>
<br>
<br>
[1] <a href="http://www.python.org/dev/peps/pep-0299/" target="_blank">http://www.python.org/dev/peps/pep-0299/</a><br>
[2] <a href="http://www.python.org/dev/peps/pep-3122/" target="_blank">http://www.python.org/dev/peps/pep-3122/</a><br>
[3] <a href="http://www.python.org/dev/peps/pep-0395/" target="_blank">http://www.python.org/dev/peps/pep-0395/</a> (sort of related)<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>
advocates of freedom in prisons.  Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br>
</div>