Example 1:
V1=u ' good magic question!? '
Type (v1)-"Unicode
V1.decode ("Utf-8") # Work,because V1 is Unicode already
V1.encode ("gb2312") #work, convert from Unicode to gbk2312
Found
Decode is the conversion of the specified object to Unicode (Unicode contains utf-8,utf-16) and indicates how the object to be converted is encoded.
Encode is the process of translating Unicode objects into other encodings.
Example 2:
V1=r ' C:\abc\1.txt '
V2=r ' good magic question '
V3=r ' C:\abc\12dc\ text-txt '
V4=r ' \\rdf\azzwang\maya2013 project\imageshahah\ æ refer Chuan lu cun trajectory. jpg '
|
. Decode ("Utf-8") |
. Decode ("gb2312") |
V1 |
√ |
√ |
V2 |
X |
√ |
V3 |
X |
√ |
V4 |
√ |
X |
Found
For a string of type str, if you want to use Utf-8 to decode it is completely impossible. Therefore, we expect a method of a program to return a specific encoding (such as Unicode), in which case we can use the Encode method directly into the encoding we want, without having to decode the puzzle.
Str,unicode and gb2312 in Python