[Python-ideas] Just __main__
Matt Chaput
matt at whoosh.ca
Tue Jun 19 00:39:14 CEST 2012
> But a __main__ function misses the whole point: that a module can be
> importable and runnable, and the if statement detects the difference. If
> you simply want a function that is always invoked as the main, then just
> invoke it:
>
> def main():
> blah blah
>
> main()
>
> No need for special names at all.
I'm afraid you're the one who's missed the point... the interpreter
would only call __main__() if __name__ == "__main__"
Some people will cry "magic", but to me this is about what makes sense
when you explain it to someone, and I think __main__() makes more sense
(especially to someone with experience in other languages) than "if
__name__ == "__main__""
Matt
More information about the Python-ideas
mailing list