flush python_带有示例的Python File flush()方法
flush python
文件flush()方法 (File flush() Method)
flush() method is an inbuilt method in Python, it is used to clear/flush the internal buffer, it is best practice while working with fila handling in Python, the internal buffer can be cleared before writing/appending the new text to the file.
flush()方法是Python中的內置方法,用于清除/刷新內部緩沖區,這是在Python中處理fila處理時的最佳實踐,可以在將新文本寫入/添加到文件之前清除內部緩沖區。
Syntax:
句法:
file_object.flush()Parameter(s):
參數:
It does not accept any parameter.
它不接受任何參數。
Return value:
返回值:
The return type of this method is <class 'NoneType'>, it returns nothing.
此方法的返回類型為<class'NoneType'> ,它什么也不返回。
Example:
例:
# Python File flush() Method with Example# creating a file myfile = open("hello.txt", "w")# writing text to the file myfile.write("Hello friends, how are you?")# flushing the internal buffer myfile.flush() # writing the text again myfile.write("\nI am good, what about you?")# flushing the internal buffer myfile.flush() # writing the text again myfile.write("\nI am good too, thanks!")# closing the file myfile.close()# reading content from the file myfile = open("hello.txt", "r") print("file content...") print(myfile.read()) myfile.close()Output
輸出量
file content... Hello friends, how are you?I am good, what about you? I am good too, thanks!翻譯自: https://www.includehelp.com/python/file-flush-method-with-example.aspx
flush python
總結
以上是生活随笔為你收集整理的flush python_带有示例的Python File flush()方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《蜀四贤咏》第二十句是什么
- 下一篇: 光与夜之恋信使巡游地点怎么选择