Value Chinese dictionary python key-value pairs, printed escape character, how to solve

Today is 2019-10-02, the next day to learn the code.

python dictionary keys right there is Chinese, when printed, the escape character to find. search for a long time to resolve. Record what .useful.

Today parts of the code:

. 1  # ! / Usr / bin / Python 
2  # - * - Coding: UTF-. 8 - * - 
. 3  # difference dictionaries and lists 
4  # list is an ordered set of objects, the dictionary is a collection of unordered objects 
5  # dictionary characteristics, the dictionary data stored by {} is defined, using the key, with the key-value pairs between separate 
6  # key --key, index --value, between keys and data values: separate key - unique, only can take the string / digital / tuple values - can be of any type 
. 7 name = " small horseshoe " 
. 8  Print (name)
 . 9 xiaomati = { " name " : name,
 10            " Age " : 26 is ,
 . 11            " Gender " : " MALE ",
12           "height": 1.71,
13           "weight": 67,
14           "skin": "yellow and black"}
15 print(xiaomati)
16 
17 decoded_data = repr(xiaomati).decode('string_escape')
18 print decoded_data

Mainly repr on line 17 (**) decode ( 'string_escape') played a real power last console output.:

 Small horseshoe
 { ' name ' : ' \ xe5 \ XB0 \ x8f \ xe9 \ xA9 \ XAC \ xe8 \ xb9 \ X84 ' , ' weight ' : 67, ' Gender ' : ' MALE ' , ' Age ' : 26 is, ' height ' : 1.71, ' Skin ' : ' Yellow and Black ' }
 { ' name ' : ' small horseshoe ' , ' weight ' :67, 'gender': 'male', 'age': 26, 'height': 1.71, 'skin': 'yellow and black'}

Start searching those methods of coercion, may be the way python dictionary is not supported.

Oh, my compiler environment python2.7, python3.5 did so.

From a touch of sadness white. I wish I could one day grow into a large cattle.

Knock some code every day, recording their problems, and it is an improvement.

 

Guess you like

Origin www.cnblogs.com/ddxmt/p/11617500.html