讀取文件 open() 函數
用于打開一個文件,返回一個 file 對象,之后用相關的方法進行讀寫。
open(name[, mode[, buffering]])
mode
'r' #open for reading (default) 文件指針會在文件開頭。默認模式
'w' #open for writing, truncating the file first,只用于寫入。如文件已存在,write 會覆蓋全部文件,類似 linux 的 echo > filename,若文件不存在,創建文件。
'x' #create a new file and open it for writing
'a' #open for writing, appending to the end of the file if it exists
'b' #binary mode,二進制模式
't' #text mode (default)
'+' #open a disk file for updating (reading and writing)
'U' #universal newline mode (deprecated)
'ab' #以二進制格式打開一個文件用于追加寫入。```