<div>Thanks for the explanation of "main".   Some tutorials mention it, some don't.   I have written some not trial Python programs and have never had a real need to use that convention, but at least I understand it now.</div>

<div> </div>
<div>--Bill<br><br></div>
<div class="gmail_quote">On Wed, Dec 1, 2010 at 1:13 PM, Tim Harig <span dir="ltr"><<a href="mailto:usernet@ilthio.net">usernet@ilthio.net</a>></span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">
<div class="im">> On Wed, Dec 1, 2010 at 9:08 AM, m b <<a href="mailto:snert@hotmail.se">snert@hotmail.se</a>> wrote:<br>>>> > if __name__ == "__main__":<br>>>> > main()<br>>><br>
>> What does this mean?<br><br></div>It is a Python idiom and a good practice.  Strictly speaking it is<br>unnecessary.  Python doesn't recognize any functional initialization<br>vector other then the start of the file.  When Python loads a module,<br>
it executes anything it finds in the module scope (Anything not in the<br>body of a class or function declaration).  Using a main function is just<br>a convention.  You could just place all of your main level code in the<br>
module scope:<br>
<div class="im"><br>def Subprogram1():<br>       # code<br>def Subprogram2():<br>       # code<br>def Subprogram3():<br>       # code<br><br></div># main code<br><br>or equivilantly, always execute main():<br>
<div class="im"><br>def Subprogram1():<br>       # code<br>def Subprogram2():<br>       # code<br>def Subprogram3():<br>       # code<br></div>def main():<br>       # main code<br>main()<br><br>Both are valid from Python's point of view.<br>
<br>The 'if __name__ == "__main__":' idiom is used, because it allows the<br>module to be loaded without running main().  This is useful if you wanted<br>to use Subprogram2() from another program.  Even if you don't forsee using<br>
any of the subprograms (functions to Python), this can be useful when<br>writing test code as you can import the program as a module to test its<br>classes or functions separately.<br>
<div>
<div></div>
<div class="h5">--<br><a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br></div></div></blockquote></div><br>