Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed4a.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '__name__': 0.09; 'executed': 0.09; 'function:': 0.09; 'subject:How': 0.10; 'cc:addr :python-list': 0.11; "'__main__':": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'interpreter,': 0.16; 'optional.': 0.16; 'presume': 0.16; 'reedy': 0.16; 'top-level': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'written': 0.21; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '13,': 0.31; 'subject:some': 0.31; 'received:google.com': 0.35; 'consistent': 0.36; 'should': 0.36; 'changing': 0.37; 'nov': 0.38; 'is.': 0.60; 'name': 0.63; 'such': 0.63; 'more': 0.64; "it'd": 0.84; 'safer': 0.84; 'mean.': 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=BVeCS5/movcl0Oz8W/IQT+/rt58rR8sxpz29BTCay1I=; b=YnTVSUEOWqu+RxpYJpIW9L6OzoVdN6l2p7cOcMxBKMBhDPN2/q0wp+kQH/qjJj+4qM 8lskD93wIvOBfA69QT4MaWIENgSVzT/8T/pGdlPp4y8jgA7y/sIwR9fA+4WAEuLQL9+Y Wn0JuG5QDAYSC3IFLZ3tEyv58Q/c6x1Dz2Y/QtNl8nut7J9HpAj443bAEs3wPKEs/VMt LSTX0VBfpEucef2Ojbv1Ahr8jWeR+c30cdDC+fXAlMR1YoDiDtkbMiWJqdaYceCqrdgx ACl+fc/LHfsUqu+67E0RBYmZaCSDAfCxQH4Kth67jqbl5pBoEHQI9utGTlLa0nfpLlBf 7/BA== MIME-Version: 1.0 X-Received: by 10.42.136.133 with SMTP id u5mr1935296ict.33.1415840095487; Wed, 12 Nov 2014 16:54:55 -0800 (PST) In-Reply-To: References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> Date: Thu, 13 Nov 2014 11:54:55 +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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415840098 news.xs4all.nl 2902 [2001:888:2000:d::a6]:45863 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3883 X-Received-Body-CRC: 1566259211 Xref: csiph.com comp.lang.python:80666 On Thu, Nov 13, 2014 at 11:35 AM, Terry Reedy wrote: >> Safer - and more in line with the way >> other such functions are written - would be a dunder function: >> >> if __name__ == '__main__': __main__() > > > I presume you mean that calling __main__ implicitly would be both consistent > and safer. No code should be using that now. That's what I mean. Like changing iter.next() to iter.__next__() in Py3, it'd be using a name that emphasizes that the interpreter, not userland code, should be calling this function. Of course, it'd still be optional. Top-level code would be executed top-down, same as it now is. ChrisA