Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: How about some syntactic sugar for " __name__ == '__main__' "? Date: Sat, 15 Nov 2014 13:54:21 +0200 Organization: A noiseless patient Spider Lines: 24 Message-ID: <87ppcok7bm.fsf@elektro.pacujo.net> References: <71b9a111-283f-4006-bc9d-e35782d9888c@googlegroups.com> <54673458$0$12999$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="13403"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mOWmWUEyWwNnqmPnIavD5" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:FF6EqowWcYaqBsBNqvcoNBX/7aI= sha1:eNFhJ7Z/43LEGM/U2bEpwRLSeR8= Xref: csiph.com comp.lang.python:80820 Steven D'Aprano : > if __name__ == '__main__' or condition(): > print "still executing" > main() > > print "done loading" > > (I haven't ever done *all* of these things in a *single* file, but I > have done all these things at one time or another.) > > There's no way that any automatic system can match that for > flexibility or simplicity. Our test system has this boilerplate at the end of each test case: if __name__ == '__main__': run(test) Nobody claims it's beautiful but nobody has been overly bothered by it, either. Marko