1

I have the following code:

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}

As you can see, it is a very simple piece of code. I get a value, assign it to a dictionary and append said dict to a list.

The thing that is annoying me is that when I log the value of student_dict['name'] I can see all the characters properly.

However, when I log the whole list, its data doesn't show properly.

Why is this?

3
  • How did you set your logger handler? did you use the encoding parameter? Commented Feb 2, 2015 at 16:07
  • I haven't used the enconding parameter. I am just using the logger.info method from the TurboGears2 framework. Commented Feb 2, 2015 at 16:23
  • Do you mean the repr output you are seeing in the list? Commented Feb 2, 2015 at 16:44

1 Answer 1

3

You are seeing the repr representation of the strings in your list:

[{'name':u'M\xd3NICA MEN\xc9NDEZ GALLEGOS', 'address': u'GENERAL YAG\xdcE 32}

When you print you are seeing the str output.

They are both equal unicode strings:

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
Sign up to request clarification or add additional context in comments.

1 Comment

@Xar, no prob. You're wlcome

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.