每次我在编辑器中“运行模块”时,都会重启Python shell?

时间:2013-09-14 18:19:29

标签: restart python

我的编辑器中只有以下内容:

def main ():
    print("hello!"); //Also tried print "hello"

每次运行Run->“运行模块”时,Python shell都会重新启动并且不打印任何内容

1 个答案:

答案 0 :(得分:1)

在Python中没有默认的主要行为,所以你通常想要做的是:

def main():
    # your code

if __name__ == "__main__":  # this means that the script was an argument for the interperet
    main()
相关问题