How about these scenarios:<br><br>You are developing a relative big main with lots of functions, and you want to test it function by function.<br><br>You are developing a library module and it doesn&#39;t really have a command line function, this is a great time to run the tests.
<br><br>if __name__ == &quot;__main__&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; runTheTests()<br><br><br><div><span class="gmail_quote">On 10/26/07, <b class="gmail_sendername">Michael Tobis</b> &lt;<a href="mailto:mtobis@gmail.com">mtobis@gmail.com
</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi, Ian! Thanks for trying.<br><br>Unfortunately, I still don&#39;t actually see how main() is better than
<br>just putting what you have in main() inline under the __name__<br>conditional...<br><br>mt<br><br>On 10/26/07, Ian Bicking &lt;<a href="mailto:ianb@colorstudy.com">ianb@colorstudy.com</a>&gt; wrote:<br>&gt; Michael Tobis wrote:
<br>&gt; &gt; I agree with everything Kumar says. It could be prettier, but it&#39;s<br>&gt; &gt; extremely useful to put the<br>&gt; &gt; __name__ == &quot;__main__&quot; around code in your file that doesn&#39;t define<br>
&gt; &gt; objects or functions.<br>&gt; &gt;<br>&gt; &gt; Now that it&#39;s come up, though. what I never quite understood was the<br>&gt; &gt; extra level of indirection that many people including Guido favor.<br>&gt; &gt;
<br>&gt; &gt; ###<br>&gt; &gt; def invoke_lots_of_stuff():<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;print &quot;I represent a lot of very clever objects and functions&quot;<br>&gt; &gt;<br>&gt; &gt; def main():<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;invoke_lots_of_stuff()
<br>&gt; &gt;<br>&gt; &gt; if __name__ == &quot;__main__&quot;:<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;main()<br>&gt; &gt; ###<br>&gt; &gt;<br>&gt; &gt; What&#39;s the purpose of the extra layer provided by the main() function?<br>&gt; &gt;<br>
&gt; &gt; Also, yeah, there&#39;s a little bit of a Python activity in Chicago...<br>&gt; &gt; (Miss y&#39;all; looking forward to seeing you again in March.)<br>&gt;<br>&gt; Usually main() handles the command-line interface, which specifically
<br>&gt; parses a list of strings, and maybe calls sys.exit.<br>&gt; invoke_lots_of_stuff would generally have a Python interface, taking<br>&gt; keyword arguments and stuff that isn&#39;t a string.&nbsp;&nbsp;So when you import the
<br>&gt; code and use it from Python, you&#39;d just use invoke_lots_of_stuff() and<br>&gt; not main().<br>&gt;<br>&gt;<br>&gt; --<br>&gt; Ian Bicking : <a href="mailto:ianb@colorstudy.com">ianb@colorstudy.com</a> : <a href="http://blog.ianbicking.org">
http://blog.ianbicking.org</a><br>&gt; _______________________________________________<br>&gt; Chicago mailing list<br>&gt; <a href="mailto:Chicago@python.org">Chicago@python.org</a><br>&gt; <a href="http://mail.python.org/mailman/listinfo/chicago">
http://mail.python.org/mailman/listinfo/chicago</a><br>&gt;<br>_______________________________________________<br>Chicago mailing list<br><a href="mailto:Chicago@python.org">Chicago@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/chicago">
http://mail.python.org/mailman/listinfo/chicago</a><br></blockquote></div><br>