Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!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.019 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'scripts': 0.03; 'linux,': 0.07; 'skip:/ 10': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'systems.': 0.12; 'chained': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'script,': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'load': 0.23; 'skip:` 20': 0.24; 'cc:2**0': 0.24; 'script': 0.25; 'somewhere': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'dec': 0.30; 'specified': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:some': 0.31; 'though.': 0.31; '(e.g.': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'rather': 0.38; 'great': 0.65; 'levels': 0.65; '11:45': 0.84; 'act.': 0.84; 'ethan': 0.84; 'furman': 0.84; 'trick,': 0.84; '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=CfhKk8L42pxGaFrCWCEY2up39lSd+fSG6P0OF6rwGi4=; b=o1RHXPOOVDO5xSwkIaC+5plMrQQdqH3qWYPQE/7Kp7ww0L02X5XrxQIincF0woNPp2 cnL1lJNkG7rbhHTXyHgXsMW3I2ei39gKbGy+iI9OtV9AAozj2ehAQyW6CutEUWintMpC mXnx4Wm314HH8uR3csvM7+2muOOrw1dr89Y2dV6XvNz7nzMvmqEFgMATSa6EbLKk7YKT dNF3UW+iEpPecewNZcxQaU53PXK0EPATyL2jeWPOVjyW2pu9rYKuC0NsDKqnwogbgiWm MaSSeJLCR9dwsqy/8PcLYkSWF4LhLAeuLw6TGUZTxh0EM5g9zDKdxB5T0is4jvbV4XlV iaPQ== MIME-Version: 1.0 X-Received: by 10.50.152.104 with SMTP id ux8mr49200132igb.14.1417482922231; Mon, 01 Dec 2014 17:15:22 -0800 (PST) In-Reply-To: <547D0B8F.1090906@stoneleaf.us> References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> <5464F958.4070404@stoneleaf.us> <547CF797.4030407@stoneleaf.us> <547D0B8F.1090906@stoneleaf.us> Date: Tue, 2 Dec 2014 12:15:22 +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: 11 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1417482930 news.xs4all.nl 2857 [2001:888:2000:d::a6]:42045 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81789 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. It's a great trick, though. I once had shebangs chained something like three or four levels deep. ChrisA