使用Python显示特殊字符

时间:2016-11-27 03:03:41

标签: python python-2.7 character-encoding character

我已在文件的开头声明了编码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

我有这个有特殊字符的单词列表

wordswithspecialcharacters =  "hors-d'œuvre régal bétail œil écœuré hameçon ex-æquo niño".split()

当我使用函数来操作这些单词并打印它们时,字符很好:

def plusS (word) :
    word = word+"s"
    return word

for x in range (len(wordswithspecialcharacters)) :
    print wordswithspecialcharacters[x]

这将正确打印它们。

但如果我只是打印带有特殊字符的列表单词,我会得到:

  

[" hors-d' \ xc5 \ x93uvre",' r \ xc3 \ xa9gal',' b \ xc3 \ xa9tail',&# 39; \ XC5 \ x93il&#39 ;,   ' \ xc3 \ xa9c \ xc5 \ x93ur \ xc3 \ xa9',' hame \ xc3 \ xa7on',' ex- \ xc3 \ xa6quo',   ' NI \ XC3 \ xb1o']

我的问题:

  1. 为什么不在列表中正确显示它们?
  2. 我该如何解决这个问题?
  3. 由于

0 个答案:

没有答案
相关问题