Python if __name__ = = ' __main__ ' What's hell is it?
Python believes that all modules can be executed or import
If a module is imported by import, the caller of the module may just want to use part of the module's code instead of running it directly
If the module is running directly, like the C or Java language, you need a portal main
In order to solve this problem, the Python convention, when the module is executed, the value of __name__ is __main__, otherwise, the value of the module's name
And if __name__ = = ' __main__ ' in the Python module is similar to the C or Java language of the main function
Ps:python is committed to the readability of the program, __name__ conventions and difficult to read, perhaps one day Python will __name__ only as a module name, and in accordance with the conventional, set the module's main entrance
There are two rules in the UNIX programming Arts: 1 The design that conforms to most people's habit is OK; 2) The meaning of an object is definite, do not change to change;
Therefore, this design of Python is not OK
Python if __name__ = = ' __main__ ' What's hell is it?