Python 檔 IO

Document 對象參考手冊 Python3 實例

以下代碼演示了Python基本的檔操作,包括 open,read,write:

實例(Python 3.0+)

# Filename : test.py # author by : www.xuhuhu.com # 寫檔 with open("test.txt", "wt") as out_file: out_file.write("該文本會寫入到檔中\n看到我了吧!") # Read a file with open("test.txt", "rt") as in_file: text = in_file.read() print(text)

執行以上代碼輸出結果為:

該文本會寫入到檔中

看到我了吧!

Document 對象參考手冊 Python3 實例