Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '"__main__":': 0.09; 'decorator': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; '~ethan~': 0.09; 'subject:How': 0.10; 'def': 0.12; 'func': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'idea,': 0.31; 'omitted': 0.31; 'subject:some': 0.31; 'though.': 0.31; 'could': 0.34; 'should': 0.36; 'wrong': 0.37; 'too': 0.37; 'being': 0.38; 'implement': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'easy': 0.60; 'ian': 0.60; 'manually': 0.60; 'received:173': 0.61 Date: Thu, 13 Nov 2014 10:32:56 -0800 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 1415903581 news.xs4all.nl 2868 [2001:888:2000:d::a6]:55701 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80695 On 11/12/2014 01:51 PM, Ian Kelly wrote: > On Wed, Nov 12, 2014 at 2:33 PM, Chris Kaynor wrote: >> >> A decorator is an interesting idea, and should be easy to implement (only >> lightly tested): >> >> def main(func): >> if func.__module__ == "__main__": >> func() >> return func # The return could be omitted to block the function from >> being manually called after import. > > This calls it at the wrong time, though. [...] One decorator that won't call too early is atexit.register(). -- ~Ethan~