Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80670

Re: How about some syntactic sugar for " __name__ == '__main__' "?

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
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; 'yet.': 0.04; 'decorator': 0.09; 'imported': 0.09; 'preferable': 0.09; 'subject:How': 0.10; '>on': 0.16; 'defined,': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'imports': 0.16; 'message-id:@cskk.homeip.net': 0.16; "module's": 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'script,': 0.16; 'simpson': 0.16; 'terribly': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'module': 0.19; 'putting': 0.22; 'header:User-Agent:1': 0.23; 'aspect': 0.24; 'cheers,': 0.24; 'script': 0.25; 'defined': 0.27; 'header:In- Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'idea,': 0.31; 'overhead': 0.31; 'subject:some': 0.31; 'though.': 0.31; "we're": 0.32; "i'd": 0.34; 'could': 0.34; 'but': 0.35; 'functions.': 0.36; 'module.': 0.36; 'received:com.au': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'wrong': 0.37; 'implement': 0.38; 'nov': 0.38; 'received:211': 0.38; 'to:addr :python-list': 0.38; 'conference': 0.38; 'pm,': 0.38; 'that,': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'easy': 0.60; 'ian': 0.60; 'content-disposition:inline': 0.62; 'visit': 0.64; 'face': 0.64; 'useful.': 0.68; 'business': 0.70; 'intelligent': 0.74; 'decorate': 0.84; 'me;': 0.84
Date Thu, 13 Nov 2014 18:23:57 +1100
From Cameron Simpson <cs@zip.com.au>
To Python <python-list@python.org>
Subject Re: How about some syntactic sugar for " __name__ == '__main__' "?
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <CALwzid=i6vKUnQU1pfO3qs8H5u+_J4ff_XdkQUxt4ajN5JNYfQ@mail.gmail.com>
User-Agent Mutt/1.5.23 (2014-03-12)
References <CALwzid=i6vKUnQU1pfO3qs8H5u+_J4ff_XdkQUxt4ajN5JNYfQ@mail.gmail.com>
X-Optus-CM-Score 0
X-Optus-CM-Analysis v=2.1 cv=dMCfxopb c=1 sm=1 tr=0 a=YuQlxtEQCowy2cfE5kc7TA==:117 a=YuQlxtEQCowy2cfE5kc7TA==:17 a=ZtCCktOnAAAA:8 a=PO7r1zJSAAAA:8 a=J0QyKEt1u0cA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=pGLkceISAAAA:8 a=wfOnNFOCAAAA:8 a=4JYc0e7WAJ_-O0_-_WkA:9 a=CjuIK1q_8ugA:10
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.15765.1415864451.18130.python-list@python.org> (permalink)
Lines 28
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415864451 news.xs4all.nl 2835 [2001:888:2000:d::a6]:43832
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80670

Show key headers only | View raw


On 12Nov2014 14:51, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
>> A decorator is an interesting idea, and should be easy to implement (only
>> lightly tested): [...]
>> Just decorate the "main" function of the script with that, and it will be
>> automatically called when ran as a script, but not when imported as a
>> module.
>
>This calls it at the wrong time, though. [...]
>This would call the main function at the time it's defined, when other
>things in the main script may not have been defined yet. One could
>place the main function last, but it would be preferable not to be
>forced.

Indeed. This aspect is a deal breaker for me; I'd never use it.

I make a point of putting the module's main function right up the top, 
immediately after the imports and any "constants" (let's not dither over that 
term). I _want_ the main function to in the reader's face when they visit the 
module code. All the cogs come later.

And lots of my modules have "main" functions. Terribly useful.

Cheers,
Cameron Simpson <cs@zip.com.au>

We're in the business of putting goo on a substrate.
- overhead by WIRED at the Intelligent Printing conference Oct2006

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: How about some syntactic sugar for " __name__ == '__main__' "? Cameron Simpson <cs@zip.com.au> - 2014-11-13 18:23 +1100

csiph-web