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


Groups > comp.lang.python > #81812

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'scripts': 0.03; 'linux,': 0.07; "'no": 0.09; 'skip:/ 10': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'systems.': 0.12; '>on': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 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; 'wrote:': 0.18; '>>>': 0.22; 'mike': 0.22; 'cc:addr:python.org': 0.22; 'load': 0.23; 'header:User-Agent:1': 0.23; 'script.': 0.24; 'skip:` 20': 0.24; 'cheers,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; "i've": 0.25; 'script': 0.25; 'somewhere': 0.26; 'header:In-Reply- To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'dec': 0.30; 'specified': 0.30; "i'm": 0.30; 'subject:some': 0.31; '(e.g.': 0.33; 'could': 0.34; 'but': 0.35; 'received:com.au': 0.36; 'that!': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'received:211': 0.38; 'issue': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; 'sure': 0.39; 'ago,': 0.61; 'content-disposition:inline': 0.62; '11:45': 0.84; 'act.': 0.84; 'ethan': 0.84; 'furman': 0.84; 'hardcore': 0.84; 'mice': 0.84; 'releases.': 0.91
Date Wed, 3 Dec 2014 07:47:25 +1100
From Cameron Simpson <cs@zip.com.au>
To Ethan Furman <ethan@stoneleaf.us>
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 <547D91A7.4090909@stoneleaf.us>
User-Agent Mutt/1.5.23 (2014-03-12)
References <547D91A7.4090909@stoneleaf.us>
X-Optus-CM-Score 0
X-Optus-CM-Analysis v=2.1 cv=BdjhjNd2 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=A92cGCtB03wA:10 a=QrVWhbZvAAAA:8 a=wZJ7l0roOB-8VU7f0vwA:9 a=CjuIK1q_8ugA:10
Cc python-list@python.org
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.16501.1417554915.18130.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1417554915 news.xs4all.nl 2861 [2001:888:2000:d::a6]:52008
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81812

Show key headers only | View raw


On 02Dec2014 02:17, Ethan Furman <ethan@stoneleaf.us> wrote:
>On 12/01/2014 05:15 PM, Chris Angelico wrote:
>> On Tue, Dec 2, 2014 at 11:45 AM, Ethan Furman wrote:
>>> Put the above somewhere in your path (e.g. /usr/local/bin), make it 
executable, and then instead of shebanging your
>>> scripts with `/usr/local/bin/python` you can use `/usr/local/bin/py_main`, which will load and execute the script,
>>> calling script.main as its last act.
>>
>> Be aware that this trick (shebanging to a script rather than a binary)
>> isn't specified by the POSIX standard. It works on Linux, but I don't
>> know about other systems.
>
>Ah, thanks for that!

I'm pretty sure I've used systems where you could not shebang to a script.  
Solaris IIRC. Several years ago, might not be an issue on modern releases.

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

For reading rec.moto, I use one of those carbon-fiber Logitech mice w/a
little 'No Fear' sticker on it. - Mike Hardcore DoD#5010 <moike@netcom.com>
                                  Apologies to Primus

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-12-03 07:47 +1100

csiph-web