【发布时间】:2017-09-06 08:18:02
【问题描述】:
文件内容如下,文件编码为utf-8:
cd232704-a46f-3d9d-97f6-67edb897d65f b'this Friday, Gerda Scheuers will be excited \xe2\x80\x94 but she\xe2\x80\x99s most excited about the merchandise the movie will bring.'
这是我的代码:
with open(file, 'r') as f_in:
for line in f_in:
tokens = line.split('\t')
print(tokens[1])
我想得到正确的答案 - “这个星期五,Gerda Scheuers 会很兴奋 - 但她最兴奋的是这部电影将带来的商品。”
print(b'\xe2\x80\x94'.decode('utf-8')) #convert into ASCII
但我无法从文件中读取字节。如果我打开一个带有字节的文件,我需要解码该行来拆分它。
【问题讨论】:
标签: python string python-3.x byte