撇号变成\ x92

时间:2013-03-22 06:26:46

标签: python python-2.7 apostrophe

mycorpus.txt

Human where's machine interface for lab abc computer applications   
A where's survey of user opinion of computer system response time

stopWords.txt中

let's
ain't
there's

以下代码

corpus = set()
for line in open("path\\to\\mycorpus.txt"):
    corpus.update(set(line.lower().split()))
print corpus

stoplist = set()
for line in open("C:\\Users\\Pankaj\\Desktop\\BTP\\stopwords_new.txt"):
    stoplist.add(line.lower().strip())
print stoplist

给出以下输出

set(['a', "where's", 'abc', 'for', 'of', 'system', 'lab', 'machine', 'applications', 'computer', 'survey', 'user', 'human', 'time', 'interface', 'opinion', 'response'])
set(['let\x92s', 'ain\x92t', 'there\x92s'])

为什么撇号在第二组中变为\ x92 ??

1 个答案:

答案 0 :(得分:13)

窗口1252编码中的代码点92(十六进制)是Unicode代码点2019(十六进制),即“右单引号”。这看起来很像撇号,很可能是你在stopwords.txt中的实际角色,我从python解释的方式中猜到了,在windows-1252中编码或者共享ASCII的编码和代码点值。

'vs'