[英]How to write data to a file continuously without blocking main loop in Python
[英]Python continuously write and save new data to file
我正在嘗試將數據連續寫入文件到文件末尾,以便數據在寫入后立即可供讀取,但似乎在沒有關閉文件的情況下更改不會被交換。 每次腳本循環時我都可以打開和關閉文件,但我認為這是一個壞主意,必須有一種方法可以在每個循環結束時提交更改
target = open("file.txt","a")
with open('test.raw',"rb") as f:
byte = f.read(160)
while byte != b"":
byte = f.read(160)
target_speech.write(data_value)
如何在循環內提交這些更改?
在target.write(...)
之后立即使用target.flush()
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.