Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'advice.': 0.05; 'function,': 0.07; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; 'executed': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'f()': 0.16; 'idle,': 0.16; 'instance)': 0.16; 'reedy': 0.16; 'wrote:': 0.16; 'jan': 0.19; 'programming': 0.20; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'command': 0.24; '(in': 0.26; 'function': 0.27; 'import': 0.28; 'module.': 0.29; 'imported': 0.30; 'usual': 0.31; 'anyone': 0.32; 'initial': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.33; 'header :User-Agent:1': 0.34; 'yourself.': 0.34; 'things': 0.34; 'another.': 0.34; 'test.': 0.34; 'header:X-Complaints-To:1': 0.35; 'file': 0.36; 'statements': 0.37; 'run': 0.37; 'two': 0.37; 'received:org': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'header :Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'bottom': 0.64; 'isolated': 0.84; 'technique': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: about if __name == '__main__': Date: Sun, 28 Aug 2011 17:35:24 -0400 References: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20110812 Thunderbird/6.0 In-Reply-To: <5dde58ef-f68e-4e62-a2c8-125bf6c35270@x11g2000prk.googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1314567382 news.xs4all.nl 2484 [2001:888:2000:d::a6]:55340 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:12355 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