Python檔案操作中 r+ 引數的用法
阿新 • • 發佈:2020-12-30
技術標籤:Python程式設計檔案和異常
【演算法程式碼】
寫法一:
filename="C:\\test.txt"
with open(filename,'r+') as file_object:
file_object.read()
file_object.write("\n ...... ")
寫法二:
filename="C:\\test.txt" with open(filename,'r+') as file_object: file_object.write("\n ...... ") file_object.readlines()
上述兩種寫法,都可以實現往已有檔案中新增內容的功能(類似於將上面的引數'r+'改為'a')。