GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — article/python/python_main.py at master · pythonpeixun/article

Expand file tree

/

python_main.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
13 lines (11 loc) · 506 Bytes
/

python_main.py

Copy path

File metadata and controls

13 lines (11 loc) · 506 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
#这样理解python中的if __name__ == '__main__':
用图片说明python中的if __name__ == '__main__':
模块都有一个变量__name__,可以在模块中print __name__的值看来本模块独立执行的值为__main__,
被其它模块导入执行的值为该模块(foo.py)的名字foo.
if语句有2个作用:
1、可以在这个if下测试函数或类。
2、防止模块被导入时,函数或类的代码被执行2次。
![](main-1.png)
![](main-2.png)
![](main-3.png)
![](main-4.png)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.