A solution to the output of a list or dictionary containing UTF-8 encoded Chinese in python

Today, when debugging the program, I encountered a coding problem. After tossing for a long time, I saw a blog: Click to open the link  to solve the problem. Now the excerpt is as follows, so as to avoid the same problem in the future.

In python below a list (list) or dictionary containing Chinese strings, using print directly will produce the following results:

dict = {"asdf": "Our python study"}
print dict
{'asdf': '\xe6\x88\x91\xe4\xbb\xac\xe7\x9a\x84python\xe5\xad\xa6\xe4\xb9 \xa0'}
is very inconvenient when outputting the processed data structure, you need to use the following method to output:
import json
print json.dumps(dict, encoding="UTF-8", ensure_ascii=False)
{"asdf": "our python learning"}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324452864&siteId=291194637