“脚本和模块”的版本间差异
跳到导航
跳到搜索
(创建页面,内容为“*模块不能直接运行 *脚本可以 *参考http://blog.csdn.net/kenkywu/article/details/6743462 创建一个test.py def test2(): print "test2 is running"...”) |
(没有差异)
|
2017年9月8日 (五) 09:50的最新版本
- 模块不能直接运行
- 脚本可以
- 参考http://blog.csdn.net/kenkywu/article/details/6743462
创建一个test.py
def test2(): print "test2 is running" if __name__ == "__main__":#自运行时调用该程序块 print "test main is working"
if __name__ == "test":#import时调用该程序块 print "test is invoked"
>>>python test.py test main is working >>>import test test is invoked >>> test.test2()
print "test2 is running"