The problem rises when I write an unicode character into a file then try to decode the character after read back. The unicode character 13 is written into a file. However when the character is read from the file, the character is interpreted as 10. The code and the result are shown below. Other unicode characters don't seem to have this problem.
# write unicode character 13 into file
a = chr(13)
ftest = open("test13.txt","w", encoding='utf-8')
ftest.write(a)
ftest.close()
# Read the character in file in binary format
print("file in binary:")
f1 = open("test13.txt", "rb")
print(ord(f1.read(1)))
# read the character in file as text
print("file in text:")
f1 = open("test13.txt", "r", encoding='utf-8')
print(ord(f1.read(1)))
# convert character without file
print("directly convert without write to file:")
b = ord(a)
print(b)
Result:
file in binary:
13
file in text:
10
directly convert without write to file:
13