bek*_*eka 2 python flask python-2.7
我有问题从我的烧瓶开发服务器(win7)将数据写入文件,
@app.route('/')
def main():
fo = open("test.txt","wb")
fo.write("This is Test Data")
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
为什么这不适用于烧瓶?
Ash*_*ary 10
您应该flush输出到文件或close文件,因为数据可能仍然存在于I/O缓冲区中.
更好地使用该with语句,因为它会自动为您关闭文件.
with open("test.txt","wb") as fo:
fo.write("This is Test Data")
Run Code Online (Sandbox Code Playgroud)