if __name__ == described in python python '__main__' if __name__ == described in '__main__' of

This is the file that the implementation of this code is located. If the file is another file is called as a module, which does not execute code inside. 
Only execute this file, if the inside of the statement will be executed. This feature can often be used for testing.

python, when opening a .py file, often see at the bottom of the code if __name__ == '__main__' :, now to explain its role, 
modules are objects, and all modules have a built-in property __name__.

__Name__ value of a module depends on how the application module. If import a module,
then the value of the module is usually __name__ module file name, without the path or file extension.

But also can be made directly run the module as a standard procedure, in this case, __name__ value will be a special default "__main__".
Directly in the cmd .py files, the values are __name__ '__main__'; after import in a file .py, __ name__ value is not '__main__'; the
so with if __name__ == '__main__' to whether the judgment is running the .py file directly.
This is the file that the implementation of this code is located. If the file is another file is called as a module, which does not execute code inside. 
Only execute this file, if the inside of the statement will be executed. This feature can often be used for testing.

python, when opening a .py file, often see at the bottom of the code if __name__ == '__main__' :, now to explain its role, 
modules are objects, and all modules have a built-in property __name__.

__Name__ value of a module depends on how the application module. If import a module,
then the value of the module is usually __name__ module file name, without the path or file extension.

But also can be made directly run the module as a standard procedure, in this case, __name__ value will be a special default "__main__".
Directly in the cmd .py files, the values are __name__ '__main__'; after import in a file .py, __ name__ value is not '__main__'; the
so with if __name__ == '__main__' to whether the judgment is running the .py file directly.

Guess you like

Origin www.cnblogs.com/maaosheng/p/11619026.html