python中的__name__ == "__main__" 有什么作用?

来源:互联网 发布:steam无法连接到网络 编辑:程序博客网 时间:2024/04/29 12:03

原文来自: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的代码了)。

原创粉丝点击