1.開啟文件,讀所有內容
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
.讀取固定位元組
file_object = open('abinfile', 'rb')
try:while True:
chunk break do_something_with(chunk)
finally:
file_object .close( )
3.讀取檔案一行
f = open("D:\test\BlueSoftSetup.log","r")
try:
readline() if line: print(line) f.close(); 4.寫檔案寫文字檔案output = open('data', 'w')
寫二進位檔案output = open('data', 'wb')
追加寫入檔案output = open('data', 'w+')
追加寫檔案output = open('data', 'w+')
寫入資料
file_object = open('thefile.txt', 'w')
file_object.close( )