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

Luk*_*uke 8 python unicode character-encoding

所以我有一个来自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缓冲区错误.谢谢.

Rah*_*hul 12

尝试openencodingutf-8:

with open("oblivion.txt", "r", encoding='utf-8') as bookFile:
    wordList = bookFile.readlines()
Run Code Online (Sandbox Code Playgroud)