Under Python, a list or dictionary that contains a Chinese string, using print directly shows the following results:
Dict = {"ASDF": "Our Python Learning"}
Print Dict
{' asdf ': ' \xe6\x88\x91\xe4\xbb\xac\xe7\x9a\x84python\xe5\xad\xa6\xe4\xb9\xa0 '}
It is inconvenient to output a well processed data structure and needs to be output using the following methods:
Import JSON
Print Json.dumps (dict, encoding= "UTF-8", Ensure_ascii=false)
{"ASDF": "Our Python Learning"}
Note the above two parameters of my experience:
If there are dict, it's okay. I took it from the MONGO, so I needed json.loads, but there was always a problem. So this plan is not for me.
If it is a string, direct output or
Print Str.encode ("UTF-8")
Used for other encodings as well. Try it quickly.
In editing a scheme for someone else. Unauthenticated.
All_symptom Content
[Python] View plaincopy the code to see the snippet derived from my Code slice
[u ' \u773c ', U ' \u8179\u90e8 ', U ' \u4e94\u5b98 ', U ' \u53e3\u8154 ', U ' \u8179\u90e8 ',
U ' \u53e3\u8154 ']
[Python] View plaincopy the code to see the snippet derived from my Code slice
Str_symptom = str (all_symptom). Replace ("u\", "\")
Str_symptom.decode ("Unicode-escape") my experience
This program is my later use of the program, uncertainty efficiency. But it works.
my answer is Str_symptom.decode ("Unicode-escape"). Encode ("Utf-8"). After decoding with Unicode, use the Utf-8 code.