python中的__name__ == "__main__" 有什么作用?
2013-11-26 21:58
387 查看
原文来自:http://stackoverflow.com/questions/419163/what-does-if-name-main-do
http://ibiblio.org/g2swap/byteofpython/read/module-name.html
appropriate actions.
总结下,就是看 是不是自己模块直接运行(如果是,就运行if下面部分的代码),还是被加载进去运行(就不运行if的代码了)。
http://ibiblio.org/g2swap/byteofpython/read/module-name.html
How It Works
Every Python module has it's__name__defined and if this is
'__main__', it implies that the module is being run standalone by the user and we can do corresponding
appropriate actions.
总结下,就是看 是不是自己模块直接运行(如果是,就运行if下面部分的代码),还是被加载进去运行(就不运行if的代码了)。
相关文章推荐
- 转:python重定向标准输入、标准输出和标准错误
- Python基于OpnenCV实现人脸识别
- 【Python】一、除法问题及基本操作(逻辑与,if替代switch)及支持中文打印
- python学习笔记:三
- python学习笔记:二
- mysql python 汉字乱码的解决方案
- Python操作MySQL以及中文乱码的问题
- 转:使用 python Matplotlib 库 绘图 及 相关问题
- Python调用MySQLdb插入中文乱码的问题
- Python 删除目录中特定文件
- python操作MySQL数据库
- Selenium-Webdriver(python) (七) --- 动态码处理
- socket client deamon
- Selenium-Webdriver(python) (六) --- Unittest框架分析
- Python填坑记——对象引用
- python中文分词工具——结巴分词
- Python抓取框架Scrapy入门教程
- python cPickle的使用
- python的logging模块
- 转:Python装饰器学习