您的位置:首页 > 编程语言 > Python开发

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

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的代码了)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: