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't really have a command line function, this is a great time to run the tests.
<br><br>if __name__ == "__main__"<br> runTheTests()<br><br><br><div><span class="gmail_quote">On 10/26/07, <b class="gmail_sendername">Michael Tobis</b> <<a href="mailto:mtobis@gmail.com">mtobis@gmail.com
</a>> 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'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 <<a href="mailto:ianb@colorstudy.com">ianb@colorstudy.com</a>> wrote:<br>> Michael Tobis wrote:
<br>> > I agree with everything Kumar says. It could be prettier, but it's<br>> > extremely useful to put the<br>> > __name__ == "__main__" around code in your file that doesn't define<br>
> > objects or functions.<br>> ><br>> > Now that it's come up, though. what I never quite understood was the<br>> > extra level of indirection that many people including Guido favor.<br>> >
<br>> > ###<br>> > def invoke_lots_of_stuff():<br>> > print "I represent a lot of very clever objects and functions"<br>> ><br>> > def main():<br>> > invoke_lots_of_stuff()
<br>> ><br>> > if __name__ == "__main__":<br>> > main()<br>> > ###<br>> ><br>> > What's the purpose of the extra layer provided by the main() function?<br>> ><br>
> > Also, yeah, there's a little bit of a Python activity in Chicago...<br>> > (Miss y'all; looking forward to seeing you again in March.)<br>><br>> Usually main() handles the command-line interface, which specifically
<br>> parses a list of strings, and maybe calls sys.exit.<br>> invoke_lots_of_stuff would generally have a Python interface, taking<br>> keyword arguments and stuff that isn't a string. So when you import the
<br>> code and use it from Python, you'd just use invoke_lots_of_stuff() and<br>> not main().<br>><br>><br>> --<br>> Ian Bicking : <a href="mailto:ianb@colorstudy.com">ianb@colorstudy.com</a> : <a href="http://blog.ianbicking.org">
http://blog.ianbicking.org</a><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>><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>