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.