TAGS :Viewed: 6 - Published at: a few seconds ago

[ Dictionary corrupt the name of the key [Python] ]

My problem is that when I get input with accent then the dictionary stores different keyname, it replace the accented character wit a character code. I'm new here I accept every help. Thank you for your help!

# -*- coding: utf-8 -*-

    prodNum = int(raw_input(u"Hány terméket kíván felvenni a listába?\r\n"))
    count   = 0

    while (count < prodNum):
        prodName            = raw_input(u"Kérem üsse be a %d. termék nevét!\r\n" %(count + 1))
        encodedName = prodName.decode('utf8')
        prodVal             = int(raw_input(u"Kérem üsse be a %d. termék darabszámát!\r\n" %(count + 1))) 

        products[encodedName]  = prodVal
        count               = count + 1
except ValueError:
    print (u"Ide egy számot kellett volna írni. :)\r\n")


Hány terméket kíván felvenni a listába?
Kérem üsse be a 1. termék nevét!
Qpa Kóla
Qpa Kóla
Kérem üsse be a 1. termék darabszámát!
{u'Qpa K\xf3la': 2}

Answer 1

Printing a container prints the representation of the contents. There is no bug, merely misplaced expectations.

>>> print u'Qpa K\xf3la'
Qpa Kóla
>>> print repr(u'Qpa K\xf3la')
u'Qpa K\xf3la'