How about some syntactic sugar for " __name__ == '__main__' "?
Marko Rauhamaa
marko at pacujo.net
Sat Nov 15 06:54:21 EST 2014
Steven D'Aprano <steve+comp.lang.python at pearwood.info>:
> 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
More information about the Python-list
mailing list