Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #12355
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: about if __name == '__main__': |
| Date | 2011-08-28 17:35 -0400 |
| References | <c0025c7f-8fb1-4be6-a41b-6227aa388a53@h23g2000pra.googlegroups.com> <mailman.509.1314550323.27778.python-list@python.org> <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.518.1314567382.27778.python-list@python.org> (permalink) |
On 8/28/2011 2:56 PM, woooee wrote: > Two main routines, __main__ and main(), '__main__' in not a routine, it is the name of the initial module. > is not the usual or the common > way to do it. It is confusing and anyone looking at the end of the > program for statements executed when the program is called will find > an isolated call to main(), and then have to search the program for > the statements that should have been at the bottom of the program. > The only reason to use such a technique in Python is if you want to > call the function if the program is run from the command line, and > also call the same function if the program is imported from another. > In which case, use a name that is descriptive, not "main". And be > careful of anyone that gives you programming advice. Research these > things for yourself. As far as I know, all the Lib/test/test_xxx.py file have a test_main function, so one can write (in IDLE, for instance) from test.test_xxx import test_main as f; f() and run that test. Very handy. -- Terry Jan Reedy
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
about if __name == '__main__': Amit Jaluf <amitjaluf@gmail.com> - 2011-08-28 08:34 -0700
Re: about if __name == '__main__': Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-28 10:51 -0600
Re: about if __name == '__main__': woooee <woooee@gmail.com> - 2011-08-28 11:56 -0700
Re: about if __name == '__main__': Terry Reedy <tjreedy@udel.edu> - 2011-08-28 17:35 -0400
Re: about if __name == '__main__': Ian Kelly <ian.g.kelly@gmail.com> - 2011-08-28 17:55 -0600
Re: about if __name == '__main__': Cameron Simpson <cs@zip.com.au> - 2011-08-29 09:59 +1000
Re: about if __name == '__main__': Amit Jaluf <amitjaluf@gmail.com> - 2011-08-28 20:42 -0700
csiph-web