问题描述
Encoded text 我想从文件中读取列表,但它已全部编码并且 .encode 并没有真正起作用
import json,sys
with open('your_file.txt') as f:
lines = f.read().splitlines()
self.logger.info(lines)
self.tts.say(lines[1])
解决方法
如果您的文件使用 UTF-8 编码保存,这应该可以:
with open('text.txt',encoding = 'utf-8',mode = 'r') as my_file:
如果这不起作用,则您的文本文件的编码不是 UTF-8。用您的文件编码代替 utf-8
。 How to determine the encoding of text?
或者,如果您按原样共享输入文件,我可以为您解决。