In Python if __name__ =='__main__'

Python code files with .py suffix can be used in two ways:

The first way is to run it directly , and the other way is to import it as a module by other py files.

Through the statement "if name == 'main'
, it can be judged whether a py file is run directly or imported as a module file by other py files, and then some codes arenot executed through this judgment.The code does not want to be executed? When the file is defined as a module by the author, it inevitably contains some test code, which is not expected to be executed when the module is imported.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327017134&siteId=291194637