用户/应用程序可以通过文件将数据永久保存的硬盘中
如何用文件
open()函数源码
========= ===============================================================
Character Meaning
--------- ---------------------------------------------------------------
'r' open for reading (default)
'w' open for writing, truncating the file first
'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)
========= ===============================================================
The default mode is 'rt' (open for reading text). For binary random
access, the mode 'w+b' opens and truncates the file to 0 bytes, while
'r+b' opens the file without truncation. The 'x' mode implies 'w' and
raises an `FileExistsError` if the file already exists.
解析
控制文件读写内容的模式:t和b
强调:t和b不能单独使用,必须跟r/w/a连用
t文本(默认的模式)
1、读写都以str(unicode)为单位的
2、文本文件
3、必须指定encoding='utf-8'
b二进制/bytes
控制文件读写操作的模式
r只读模式
w只写模式
a只追加写模式
+:r+、w+、a+