Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'languages,': 0.04; 'explicitly': 0.05; 'explicit': 0.07; '"if': 0.09; "'return": 0.09; '__name__': 0.09; 'function:': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; "'__main__':": 0.16; '(which,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'invocation': 0.16; 'reedy': 0.16; 'simplest': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'thu,': 0.19; 'written': 0.21; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; '13,': 0.31; 'implicit': 0.31; 'subject:some': 0.31; 'common': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'ends': 0.38; 'nov': 0.38; 'even': 0.60; 'such': 0.63; 'become': 0.64; 'more': 0.64; 'conflicts': 0.84; 'end.': 0.84; 'safer': 0.84; 'magical': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=pDFb8H3bzMy1mR+rLtn0z+9poT2fl8Rd8s9RTrG1SPQ=; b=AqVhKfO3M5EZrrwWhJXtdaVRLaA8P5B4FtwargD79WXomejUJFVwAx9xErYC1fYjgw 5pGW2+0tXwZBP1SKiW1EQe0sru2jFFwv25lGkqzXXbjyj1he2yCdVrYe03MPsgNaJpMA rlYskeI0DpAlqYzRutXHLBKwHQ1B/ezkFgfRmb6YR7AQsBVFMSSSjCFMKroJXeBXgjaX SeLj1EtARAHB4tjXKQ9YMrBY4vMOLnf3jiFejvtElXgmVaUlG53JL12EPJh7nd0NSQTG /hM/s1vs4vTfOxbdGGqLJF7hRbEwmKGFlbWMofXtvHzAIgF8/rPd/7EX8E1a0qxmR8I6 2eyQ== MIME-Version: 1.0 X-Received: by 10.50.128.35 with SMTP id nl3mr7740920igb.34.1415834810244; Wed, 12 Nov 2014 15:26:50 -0800 (PST) In-Reply-To: References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> Date: Thu, 13 Nov 2014 10:26:50 +1100 Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 17 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415834813 news.xs4all.nl 2893 [2001:888:2000:d::a6]:52915 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3971 X-Received-Body-CRC: 3009487046 Xref: csiph.com comp.lang.python:80660 On Thu, Nov 13, 2014 at 10:19 AM, Terry Reedy wrote: > Functions have an implicit 'return None' at the end (which, in CPython, > become an explicit pair of bytecodes, even when the function already ends > with return something'. The simplest proposal is that modules have an > implicit "if __name__ == '__main__': main()" at the end. I think this would > not have to be added to the bytecode. > > This magical invocation mimics C and some other languages, and I think it > works well. Yes, but it conflicts with the existing and common usage of having that explicitly in the code. Safer - and more in line with the way other such functions are written - would be a dunder function: if __name__ == '__main__': __main__() ChrisA