[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)

Chris Angelico rosuav at gmail.com
Sun Nov 24 17:31:46 CET 2013


On Mon, Nov 25, 2013 at 3:26 AM, Philipp A. <flying-sheep at web.de> wrote:
> so i’d propose one of the following API-wise:
>
> def __main__():
>     ...
>
> @mainfunction
> def main():
>     ...

The decorator minorly worries me; what happens if you use it on two
functions? Presumably both would have to be called, in the order
they're in the file (or rather, the order the decorators are called),
but it'd be extremely confusing to try to read that code.

ChrisA


More information about the Python-ideas mailing list