Python, if __name__ == '__main__' role

Python files can be run directly, you can also import other files to use

if __name__ == '__main__' is to control the execution of the code in both cases

 

 

Every Python module contains built-in variables, when run directly, name equal to the main, on behalf of itself

 

 

__name__, when the module is called execution, name is the file name

 

 

Guess you like

Origin www.cnblogs.com/jiyu-hlzy/p/11785520.html