运行python文件 - 什么功能是主要的?

atp*_*atp 17 python

我有简单的python脚本'first.py':

#first.py
def firstFunctionEver() :
    print "hello"

firstFunctionEver()
Run Code Online (Sandbox Code Playgroud)

我想使用以下方法调用此脚本:python first.py并让它调用firstFunctionEver().但是,脚本是丑陋的 - 我可以将调用放入哪个函数firstFunctionEver()并在加载脚本时运行它?

Ste*_*joa 40

if __name__ == "__main__":
    firstFunctionEver()
Run Code Online (Sandbox Code Playgroud)

更多的文档在这里.


Ken*_*Ken 10

if __name__ == '__main__':
    firstFunctionEver()
Run Code Online (Sandbox Code Playgroud)