我刚开始学习Flask,对代码有些困惑
app = Flask(__name__)
print(__name__)
if __name__ == '__main__':
print(__name__) # I add two more lines here
print("ok")
app.run()
文件名是app.py。当我在终端中使用命令python app.py
时,结果为
__main__
__main__
ok
...flask running information...
但是当我在PyCharm中运行代码时,我得到的是:
...flask running information...
app
如果我这样修改代码:
app = Flask(__name__)
print(__name__)
if __name__ != '__main__':
print(__name__) # I add two more lines here
print("ok")
app.run()
结果是:
...flask running information...
app
app
ok
我在终端上执行了此操作,烧瓶无法启动,结果是:
__main__
所以终端中_ name _等于'_ main _'的结果,_ name _不等于'_ PyCharm中的“ main _”,烧瓶在两种情况下都在PyCharm中运行,但在命令行中却不相同?