[Python-ideas] Replacing the if __name__ == "__main__" idiom (was Re: making a module callable)
Antoine Pitrou
solipsis at pitrou.net
Sat Nov 23 02:51:53 CET 2013
On Fri, 22 Nov 2013 17:45:22 -0800
Sean McQuillan <mcquillan.sean at gmail.com>
wrote:
> Adding a mainfunction decorator was mentioned in the other thread, seemed
> interesting so I coded up a simple example to see how it works.
>
> https://github.com/objcode/mainfunction/blob/master/mainfunction/mainfunction.py
>
> From the README:
>
> @mainfunction
> def main():
> print "Hello, World."
>
> vs:
>
> if __name__ == '__main__':
> print "Hello, World."
>
>
> After playing with it briefly, I'm not sure it's a clear spelling win as
> decorators are a fairly advanced topic to a new programmer. If statements
> are one of the first programming constructs a new programmer learns - and
> they don't leave a "magic taste".
Indeed, I think the current idiom is much better.
Regards
Antoine.
More information about the Python-ideas
mailing list