_name_ of the module

Source: Internet
Author: User

__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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.