1

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!

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

products={}
try:
    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')
        print(encodedName)
        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")

print(products)

Output:
Hány terméket kíván felvenni a listába?
1
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!
2
{u'Qpa K\xf3la': 2}

1 Answer 1

2

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

2 Comments

Thank you for your help. Could you tell me, that how can I print the contents of the dictionary in an accented format?
I found the solution: for key in products.iterkeys(): print key

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.