how can i decode unicode string in python? -


wikipedia api encodes string unicode format

"golden globe award best motion picture \u2013 drama" 

how can convert to

"golden globe award best motion picture – drama" 

the wikipedia api returns json data, use json module decode:

json.loads(inputstring) 

demo:

>>> import json >>> print json.loads('"golden globe award best motion picture \u2013 drama"') golden globe award best motion picture – drama 

if instead have string starts u'', have python unicode value , looking @ representation of string:

>>> json.loads('"golden globe award best motion picture \u2013 drama"') u'golden globe award best motion picture \u2013 drama' 

just print value have python encode terminal codec , represent em-dash character in format terminal understand.

you may want read python , unicode , encodings before continue, if not understand difference between unicode value , byte strings:


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -