ale*_*cxe 94 python file-io file
在这里几次我已经看到人们使用rt
和wt
模式来读写文件.
例如:
with open('input.txt', 'rt') as input_file:
with open('output.txt', 'wt') as output_file:
...
Run Code Online (Sandbox Code Playgroud)
我不明白的方式记载,但因为open()
不抛出一个错误-看起来几乎是合法的使用.
是什么状况,使用wt
vs w
和 rt
vs 之间有什么区别r
吗?
dev*_*ull 165
t
指文本模式.r
和rt
或之间没有区别w
,wt
因为文本模式是默认模式.
记录在这里:
Character Meaning
'r' open for reading (default)
'w' open for writing, truncating the file first
'x' open for exclusive creation, failing if the file already exists
'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 newlines mode (deprecated)
Run Code Online (Sandbox Code Playgroud)
默认模式是'r'
(打开以读取文本,同义词'rt'
).