Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Bill Allen
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. --Bill On Wed, Dec 1, 2010 at 1:13 PM, Tim Harig wrote: > > On Wed, Dec 1, 2010

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Tim Harig
> On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >>> > if __name__ == "__main__": >>> > main() >> >> What does this mean? It is a Python idiom and a good practice. Strictly speaking it is unnecessary. Python doesn't recognize any functional initialization vector other then the start of the file. W

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Steve Holden
On 12/1/2010 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > It's a standard way of allowing programs to test themselves. When a module is imported its __name__ attribute us bound to the name of the module. When the module is run

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Hanif Jameel
On 01/12/2010 17:08, m b wrote: > > > > if __name__ == "__main__": > > main() What does this mean? /Mikael Python will not cause the main() function to run automatically when you execute the script, it has to be called. __name__ is a special variable which is set by the python interpre

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Benjamin Kaplan
On Wed, Dec 1, 2010 at 12:08 PM, m b wrote: > > >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? > > /Mikael > Every module has an attribute called __name__. Normally, it's the name of the module itself. However, the module being run as a script (rather than imported) is

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Jean-Michel Pichavant
m b wrote: > > > > if __name__ == "__main__": > > main() What does this mean? /Mikael __name__ is an attribute of the module. Usually it is set to the module name, except when the module is acutally executed as the entry point, in that case __name__ is set to '__main__'. foo.py: print __n

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Chris Rebert
On Wed, Dec 1, 2010 at 9:08 AM, m b wrote: >> > >> > if __name__ == "__main__": >> > main() > > What does this mean? See http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm (which is the 3rd Google hit for "__main__") Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list

RE: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread m b
> > > > if __name__ == "__main__": > > main() What does this mean? /Mikael -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Jean-Michel Pichavant
Tim Harig wrote: On 2010-12-01, goldtech wrote: Start Main Global Var Subprogram1 Subprogram2 Subprogram3 End of Main End module_wide_var = value def Subprogram1: # code def Subprogram2: # code def Subprogram3: # code def main: Subpr

Re: Python's equivalent to Main calling program and subprograms

2010-12-01 Thread Tim Harig
On 2010-12-01, goldtech wrote: > Start > Main > Global Var > Subprogram1 > Subprogram2 > Subprogram3 > End of Main > End module_wide_var = value def Subprogram1: # code def Subprogram2: # code def Subprogram3: # code def main: Subprogram1()

Python's equivalent to Main calling program and subprograms

2010-12-01 Thread goldtech
Hi, Could someone link me to info - I'm sure this is commonly done: "Long ago" with Fortran and Pascal there was a pattern used a lot. It was like: Start Main Global Var Subprogram1 Subprogram2 Subprogram3 End of Main End The global var was a var that all the subprograms could a