python decoding of Unicode

print:

Print ( ' I love you ' .encode ( ' utf8 ' ))

Get Unicode encoding:

b'\\u6211\\u559c\\u6b22\\u4f60

 

The above code is assigned to the decoded str:

# The Unicode 
S1 = ' \\ u6211 u6b22 \\ \\ \\ u559c u4f60 ' 

# Switch UTF8 (plain text) 
Print (s1.encode ( ' UTF8 ' ) .decode ( ' unicode_escape ' ))
 # Switch utf- 8 encoding 
Print (s1.encode ( ' UTF8 ' ) .decode ( ' unicode_escape ' ) .encode ( ' UTF8 ' ))

Output:

I love you 
b ' \ XE6 \ X88 \ x91 \ xe5 \ X96 \ x9c \ XE6 \ XAC \ xa2 \ XE4 \ XBD \ XA0 '

 

Guess you like

Origin www.cnblogs.com/feiquan/p/11117703.html