Python 首頁 | Data Type | Function | 檔案處理 |
參見 Python初學 檔案處理
f = open(file_name, "模式")
f.close()
f.read()
f = open("test.txt", "r") words = f.read() print(words) f.close()
f = open("test.txt", "r") first_line = f.readline() second_line = f.readline() print(second_line, first_line, sep = "\n") f.close()
f = open("test.txt", "r") f_list = f.readlines() print(f_list) f.close()
f.write()
f = open("test.txt", "w") f.write("Try to use file.write()\nHail HYDRA") f.close() f = open("test.txt", "r") words = f.read() print(words) f.close()