如何像打印字符串一样返回字符串



我有一个使用请求模块获得的txt文件。

import requests
response = requests.get(url)
str = response.txt

如果我打电话给str,我会得到

'testnone'

作为输出(错误格式(

如果我返回str,我会得到

'test/none'

作为输出(错误格式(

如果我打印str,我会得到

test
one

作为输出(右格式(

如何在不打印的情况下获得print str的格式?

我必须使用退货我不能使用打印,也不能使用返回打印

这是因为这是一个烧瓶应用程序,所以格式必须是

@app.route('/')
def home():
return str

@app.route('/')
def home():
return render_template('home.html', value=str)

使用repr,请参阅以下内容:

>>> print(repr("your stringn"))
"your stringn"

相关内容

最新更新