【发布时间】:2017-06-03 16:30:10
【问题描述】:
使用以下 MWE:
with open('a','w') as f:
f.write('\r')
with open('a','r') as f:
print(ord(f.read()))
我得到以下输出:
$ python2 test.py
13
$ python3 test.py
10
你能解释一下为什么吗?据我所知,13 是 \r 在 ascii 和 UTF-8 中的预期十进制数。
【问题讨论】:
-
ord('\n')会给你10个。ShadowRanger已经解释了原因。
标签: python python-3.x newline python-2.x line-endings