Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!novso.com!newsfeed.xs4all.nl!newsfeed2.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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; '"__main__":': 0.09; '__name__': 0.09; 'main()': 0.09; 'subject:How': 0.10; 'def': 0.12; 'blocks': 0.16; 'function?': 0.16; 'redundant': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'replacing': 0.19; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'message-id:@mail.gmail.com': 0.30; 'along': 0.30; 'code': 0.31; 'lines': 0.31; 'proposing': 0.31; 'subject:some': 0.31; 'another': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; '12,': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'simple': 0.61; "you're": 0.61; 'here': 0.66; 'goal': 0.75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=cJxI5TrXnaccyRGxcjIj9H7P8WKqAAdzJvpJrCwlO6Q=; b=ZRgG5KY48BeLLHU+sgreBOVBGe+tnlL+l2SS/7Wy9O9kkvIcsdEr54+ugcOrT5J+XN Wd1UKeZ5FzqkDYHQQUHc2CYTLn/P4ngzO28PKKyytRPGVlHPMfLoSJUzjJvnajAtY+Rw ZGi/rwqvbNYcF5INNwBkHrwnMmOH+9IuLIRH4W0AAmxZOVa/7cDWK8m4xhHWiDMXCG6p z36HZwLFmYizAhoZ6LT3UX+rksLRQMW7fryh9xipmaKvFOdGG7eM+XO/UPJR7gKKYHoy aTKkj20Gf8VC7F1IeKi8oA1e453/VQZvxKv3FIQM2wLZyRIX0yAr1UoIgswuCxrp4NpT HE3A== X-Received: by 10.69.31.138 with SMTP id km10mr51674453pbd.6.1415830790007; Wed, 12 Nov 2014 14:19:50 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> From: Ian Kelly Date: Wed, 12 Nov 2014 15:19:09 -0700 Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? To: Python 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415830799 news.xs4all.nl 2908 [2001:888:2000:d::a6]:33821 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80644 On Wed, Nov 12, 2014 at 3:09 PM, Chris Kaynor wrote: > I was thinking along the lines of replacing: > > if __name__ == "__main__": > <<>> > > with > > @main > def myFunction() > <<<> > > Both blocks of code will be called at the same time. 99% of the time the content of <<>> is just "main()", so then you're proposing replacing this: if __name__ == "__main__": main() with this: @main def myFunction(): my_main() Which feels redundant to me. Why have a function here that does nothing but call another function? I think if this is the goal then a simple predicate would be clearer: if is_main_module(): main()