the python comprising UTF-8 encoding of a list or dictionary of Chinese output

List (list) or a dictionary in python under a string that contains Chinese, directly print the following results occur:
 
>>> dict = { "asdf": "We learn python"}
>>> print dict
{ 'Asdf': '\ xe6 \ x88 \ X91 \ xe4 \ xbb \ xac \ xe7 \ x9a \ x84python \ xe5 \ XAds \ xa6 \ xe4 \ xb9 \ xa0'}
Inconvenient when outputting processed data structure needs to be output using the following method:
>>> import json
>>> print json.dumps(dict, encoding="UTF-8", ensure_ascii=False)
{ "Asdf": "We learn python"}
Note that the above two parameters
 
If a string, or direct output
print str.encode("UTF-8")
 
Also used for other codes.
 
s.decode() u.encode()

Guess you like

Origin www.cnblogs.com/leo6099/p/11836715.html