Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธี Flush Internal Buffer ใน Python

Python buffer การเขียนไฟล์ (file.write คืนค่าก่อนเขียนจริง) เพื่อความเร็ว ใช้ file.flush() บังคับ flush ทันที

with open("my_file.txt", "w+") as file:
    file.write("foo")
    file.write("bar")
    file.flush()