“的意义是什么? #!flask / bin / python“在烧瓶? [英] what is the significance of " #!flask/bin/python " in flask?

查看:274
本文介绍了“的意义是什么? #!flask / bin / python“在烧瓶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这行#!flask / bin / python 被添加到这段代码的顶部?

 from flask import Flask 

app = Flask(__ name__)

@ app.route('/')
def index ():
返回Hello,World!
$ b $ if if __name__ =='__main__':
app.run(debug = True)

当我删除它时,出现以下错误:

  from:无法读取/ var / mail /烧瓶
./app.py:第3行:意外标记附近的语法错误('
./app.py:第3行:`app = Flask(__ name__)'


解决方案

code> shebang 在UNIX / UNIX操作系统上,它基本上告诉你的shell执行脚本的是哪一个可执行文件(在你的情况下是python),如果没有它,shell直接执行脚本因为它不理解Python代码,所以会引发错误。


why this line #!flask/bin/python is added on the top of this code?

from flask import Flask

app = Flask(__name__)

@app.route('/')
def index():
    return "Hello, World!"

if __name__ == '__main__':
    app.run(debug=True)

I got following error when I removed it

from: can't read /var/mail/flask
./app.py: line 3: syntax error near unexpected token `('
./app.py: line 3: `app = Flask(__name__)'

解决方案

#! is a shebang. On UNIX/UNIX like operating systems it basically tells your shell which executable (python in your case) to execute the script with. Without it, the shell is executing the script directly and since it does not understand Python code, it raises an error.

这篇关于“的意义是什么? #!flask / bin / python“在烧瓶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆