__name__ of the module
Each module has a name that can be used in the module to find the name of the module through a statement. This is particularly useful on an occasion-as mentioned earlier, when a module is first entered, the module's main block will be run. What if we just want to run the main block while the program itself is being used, and not run the main block when it is entered by another module? This can be done through the __name__ property of the module.
Using the __name__ of the module
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example 8.2 using the __name__ of the module
# !/usr/bin/python # Filename:using_name.py if Span style= "color: #800080;" >__name__ == " __main__ '
Output
$ python using_name.py
Being run by itself
$ python
>>> import Using_namei am being imported from another module
>>>
How it works
Each Python module has its __name__, if it is ' __main__ ', which means that the module is run by the user individually, we can do the appropriate operation.
_name_ of the module