Reputation: 665
I have a dictionary which looks like this.
{ latex schlüpfer : [455, 'latex schl\xc3\xbcpfer', 5.0, 0.0, 0.0, 24.6] }
Why is my list value at index 1 showing in a different encoding?
I've tried replacing it with the key as well as appending it and it always comes out the same.
Even when I go:
print key # latex schlüpfer
print [key] # latex schl\xc3\xbcpfer
What's going on?
I'm trying to check if the item exists but the encoding issues appear to be preventing me from doing this as I'm comparing latex schl\xc3\xbcpfer to latex schlüpfer
Upvotes: 0
Views: 43
Reputation: 114
You can try to encode your entire dictionary by using the follow code:
mydict = {k: unicode(v).encode("utf-8") for k,v in mydict.iteritems()}
This uses a dictionary comprehension.
Upvotes: 0
Reputation: 46849
objects inside a list are printed using their __repr__
method. this reproduces your output:
# coding=utf-8
s = 'latex schlüpfer'
print(s)
print(repr(s))
it prints
latex schlüpfer
'latex schl\xc3\xbcpfer'
Upvotes: 1