Discuss / Python / 中英文混杂时最好在读写文件时加上编码方式,从而确保结果正确

中英文混杂时最好在读写文件时加上编码方式,从而确保结果正确

Topic source
fpath = r'test.txt'
with open(fpath, 'x', encoding = 'utf-8') as f:
    f.write('yang们')

with open(fpath, 'r', encoding = 'utf-8') as f:
    s = f.read()
    print(s)

  • 1

Reply