0

How read method will behave in files encoded in utf, since some characters in utf have 2 bytes?

21st Jan 2016, 10:13 AM
Henrique Vianna
Henrique Vianna - avatar
1 Odpowiedź
0
I tried with filename.txt containing: abcdefghijklmnop你好Henrique and this code: file = open("filename.txt", "r") print("reading 16") print(file.read(16)) print("reading 2") print(file.read(2)) print("reading 5") print(file.read(5)) print("reading remainder") print(file.read()) file.close() I got these results: christopher@water:~/py3eg$ python3 readfiles.py reading 16 abcdefghijklmnop reading 2 你好 reading 5 Henri reading remainder que
17th Apr 2016, 8:36 PM
Christopher Gray
Christopher Gray - avatar