During network programming, you often need to print the received data in hexadecimal format for easy viewing. Today we found that there is such a simple method in Python.
>>> "Hello". encode ("hex ")
'68656c6c6f'
You can also
>>> '68656c6c6f'. Decode ("hex ")
'Hello'
I checked the manual and found these codec available.
Codec |
Aliases |
Operand type |
Purpose |
Base64_codec |
Base64, base-64 |
Byte string |
Convert operand to mime base64 |
Bz2_codec |
Bz2 |
Byte string |
Compress the operand using bz2 |
Hex_codec |
HEX |
Byte string |
Convert operand to hexadecimal representation, with two digits per byte |
Idna |
|
Unicode string |
Implements RFC 3490. New in Version 2.3. See alsoEncodings. Idna |
MBCS |
DBCS |
Unicode string |
Windows only: encode operand according to the ANSI codePage (cp_acp) |
Palmos |
|
Unicode string |
Encoding of palmos 3.5 |
Punycode |
|
Unicode string |
Implements RFC 3492. New in Version 2.3. |
Quopri_codec |
Quopri, quoted-printable, quotedprintable |
Byte string |
Convert operand to mime quoted printable |
Raw_unicode_escape |
|
Unicode string |
Produce a string that is suitable as raw Unicode literal in Python source code |
Rot_13 |
Rot13 |
Unicode string |
Returns the CAESAR-Cypher encryption of the operand |
String_escape |
|
Byte string |
Produce a string that is suitable as string literal in Python source code |
Undefined |
|
Any |
Raise an exception for all conversions. can be used as the system encoding if no automatic coercion between byte and Unicode strings is desired. |
Unicode_escape |
|
Unicode string |
Produce a string that is suitable as Unicode literal in Python source code |
Unicode_internal |
|
Unicode string |
Return the internal representation of the operand |
Uu_codec |
UU |
Byte string |
Convert the operand Using UUENCODE |
Zlib_codec |
Zip, zlib |
Byte string |
Compress the operand using Gzip |