小编Ele*_*iou的帖子

为什么文件的内容只有在关闭后才写入?

我注意到,在Python中写入文件时,一旦文件关闭,内容就会写入文件中。

例如:

with open('test.txt','w') as ffile:
    ffile.write("testing")
    time.sleep(20)
Run Code Online (Sandbox Code Playgroud)

在此示例中“等待 20 秒后将写入“ testing ”。

这是如何以及为何发生的?为什么不同时写入文件呢?

python file-io file python-3.x

0
推荐指数
1
解决办法
527
查看次数

标签 统计

file ×1

file-io ×1

python ×1

python-3.x ×1