python相同的字符串以不同的编码出现?

python相同的字符串以不同的编码出现?,python,character-encoding,Python,Character Encoding,我有以下代码: students_list = [] for student in students: student_dict = {} dict_student['nane'] = name logger.info(student_dict['name']) # prints ==> MÓNICA MENÉNDEZ GALLEGOS dict_student['address'] = address logger.info(stu

我有以下代码:

students_list = []

for student in students:

    student_dict = {}

    dict_student['nane'] = name
    logger.info(student_dict['name'])
    # prints ==> MÓNICA MENÉNDEZ GALLEGOS

    dict_student['address'] = address
    logger.info(student_dict['address'])
    # prints ==> GENERAL YAGÜE 32

    students_list.append(dict_student)

logger.info(students_list)
# prints => [{'name':u'M\xd3NICA MEN\xc9NDEZ GALLEGOS', 'address': u'GENERAL YAG\xdcE 32}
如您所见,这是一段非常简单的代码。我得到一个值,将其分配给字典,并将所述dict附加到列表中

让我恼火的是,当我记录
student_dict['name']
的值时,我可以正确地看到所有字符

但是,当我记录整个列表时,它的数据没有正确显示

这是为什么?

您看到列表中字符串的表示形式:

[{'name':u'M\xd3NICA MEN\xc9NDEZ GALLEGOS', 'address': u'GENERAL YAG\xdcE 32}
打印时,您会看到
str
输出

它们都是相等的unicode字符串:

In [1]: (l[0]["address"]) 
Out[1]: u'GENERAL YAG\xdcE 32'
In [2]: (l[0]["address"]) == u"GENERAL YAGÜE 32"
Out[2]: True

您是如何设置记录器处理程序的?您是否使用了
编码
参数?我没有使用
编码
参数。我只是在使用TurboGears2框架中的
logger.info
方法。你是说你在列表中看到的repr输出吗?@Xar,没问题。你来了