main() 函数在运行脚本时不运行 [英] main() function doesn't run when running script
本文介绍了main() 函数在运行脚本时不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#! /usr/bin/python
def main():
print("boo")
当我尝试在 Python 3.3 中运行这段代码时,它什么也没做.没有错误或任何东西.怎么了
This code does nothing when I try to run it in Python 3.3. No error or anything. Whats's wrong
[tim@tim-arch ~]$ gvim script
[tim@tim-arch ~]$ sudo chmod 775 script
[tim@tim-arch ~]$ ./script
[tim@tim-arch ~]$
推荐答案
您仍然需要调用该函数.
def main(): # declaring a function just declares it - the code doesn't run
print("boo")
main() # here we call the function
这篇关于main() 函数在运行脚本时不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文