On Sat, Oct 02, 2021 at 09:22:04AM +0000, Zbigniew Jędrzejewski-Szmek wrote:
A nice bonus is that this scheme is very close to main() in C/C++/Java and other compiled languages, so users coming in from those languages will understand this without further explanation.
I don't think they will actually understand it. What they might do is be fooled into *thinking* that they understand it, in C terms, when they don't. The entry point to a Python script is not main(), it is the top of the module. It is merely a convention that we sometimes write a main function, and call it at the bottom. And not even a strong convention: plenty of people write Python scripts with no main() function and no need to test for `if __name__ == __main__`. And there is nothing wrong with that. In C terms, this code is not even possible: print("Hello") def main(): print("Goodbye") __main__(main) print("Why are you still here? Go home!") since you cannot have code outside of a function that is called before the entry point main() (declarations and macros excempted) or after it returns. I don't think it is a good idea to give programmers coming from other languages the false impression that Python behaves the same as the language they are familiar with, when it doesn't. The entrypoint to Python scripts is not main(), it is the top of the module. -- Steve