How simple to understand Python, if __name__ == '__main__':

Brief summary:

if __name__ == '__main__':

In the module which is used to put test code, because the import module will execute the code module, but the module test code we need to perform, we only need to block the function, it is necessary to use if __name__ == '__main__ ':

When people call this module if__name__ not equal to "__main__" the

__name__ is a block path, so if__name__ __main__ is not equal, the condition is not satisfied, is not performed if __name__ == '__main__': The following code

But you go module file execution module file, __ name__ is equal to __main__, and meet the conditions, so it can be used to test

 


 

Guess you like

Origin www.cnblogs.com/ashjo009/p/12663053.html