codeObjC codeObjC - 1 year ago 100
Python Question

String Dict to Unicode coversion

I am new to python. I was wondering if there are any intuit functionality that I can use to go from string dict to unicode dict.


{'name': 'Lexus', 'model': 'GS F'}

Expected output:

{u'name': u'Lexus', u'model': u'GS F'}

Any comments / forwards to resources are welcomed.

Answer Source
>>> d={'name': 'Lexus', 'model': 'GS F'}
>>> d={k.decode('utf8'): v.decode('utf8') for k, v in d.items()}

output :

{u'model': u'GS F', u'name': u'Lexus'}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download