小编Luk*_*uke的帖子

Python:Unicode和"\ xe2\x80\x99"让我很沮丧

所以我有一个来自Google Docs的.txt文件,其中包含David Foster Wallace的"Oblivion"中的一些内容.使用:

with open("oblivion.txt", "r", 0) as bookFile:
    wordList = []
    for line in bookFile:
        wordList.append(line)
Run Code Online (Sandbox Code Playgroud)

并返回并打印wordList我得到:

"surgery on the crow\xe2\x80\x99s feet around her eyes." 
Run Code Online (Sandbox Code Playgroud)

(它会截断很多文本).但是,如果不是简单地附加wordList而不是

for line in bookFile:
    print line
Run Code Online (Sandbox Code Playgroud)

一切都很好!.read()文件也一样 - 生成的str没有疯狂的字节表示,但是我不能按照我想要的方式操作它.

我在哪里.encode()或.decode()还是什么?使用Python 2因为3给了我一些I/O缓冲区错误.谢谢.

python unicode character-encoding

8
推荐指数
1
解决办法
7585
查看次数

标签 统计

character-encoding ×1

python ×1

unicode ×1