python open mode
-
必须其一:
r, w, a
: read(默认), write, append -
可选:
b, t, +, U
: binary, text(默认), reading and writing, universal newlines mode -
rt == r, wt == w, at == a
-
r+
>>> with open('aa', 'r+') as f: ... print(f.tell()) ... 0 >>> with open('aa', 'r+') as f: ... f.readline() ... print(f.tell()) ... '0\n' 2
- read执行在前, write执行在后: 添加到最后一行
- write执行在前: 写入并替换第一行内容
-
w+ == w
-
a+ == a