Literacy Sticker---about if __name__ = = ' __main__ ' in Python

Source: Internet
Author: User
Tags python script

For __name__ variables in Python, the value of the __name__ variable varies depending on how the Python file is called. If I had a Python script called hello_world.py, when I was aiming to run the file "Python hello_world.py" directly, the value for hello_world.py's __name__ variable was "__ Main__ ". But when we put hello_world.py as a module by introducing another module to "Import Hello_world", the value of __name__ variable in hello_world.py is the python filename "hello_ World ".

Example:

1. Python script named Hello_world

2. When running the hello_world.py Python script directly

3. After the hello_world.py module is introduced into the hello_world01.py script

4. Script to run hello_worlld01.py

Literacy Sticker---about if __name__ = = ' __main__ ' in Python

Related Article

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.