The clever use of python encode and decode

  • 2020-04-02 09:18:49
  • OfStack

> > > "Hello". Encode (" hex ")
'68656 c6c6f'

The corresponding is ok

> > > '68656 c6c6f. Decode (" hex ")
'hello,'

I checked the manual and found these codec's available

The Codec

Aliases

Operand type

The 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 (link: http://www.faqs.org/rfcs/rfc3490.html). New in version 2.3. See also encodings. Idna MBCS DBCS Unicode string Windows only: Encode operand according to the ANSI codepage (CP_ACP) The palmos   Unicode string The Encoding of the PalmOS 3.5 punycode   Unicode string Implements (link: http://www.faqs.org/rfcs/rfc3492.html). New in version 2.3. quopri_codec Quotedprintable quopri, quoted - printable Byte string Convert operand to MIME quoted printable raw_unicode_escape   Unicode string Produce a string that is suitable as raw Unicode literal in (link: http://www.python.org/) source code rot_13 The 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 (link: http://www.python.org/) source code undefined   any Raise an exception for all conversions. Can be 2 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 (link: http://www.python.org/) 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


Related articles: