On this page
codecs.encode
Prev: codecs.decode | Up: codecs | Next: codecs.EncodedFile
Rel: codecs.backslashreplace_errors, codecs.Codec, codecs.CodecInfo, codecs.decode
Ref: docs.python.org — codecs.encode
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import encode
Signature & Overview
codecs.encode(obj, encoding='utf-8', errors='strict')
Encodes obj using the codec registered for encoding.
Usage
import codecs
assert codecs.encode(b"hi", "hex") == b"6869"
assert codecs.encode("hello", "rot_13") == "uryyb"
Gotchas
- Supports bytes-to-bytes and str-to-str codecs: For normal text encoding, prefer
text.encode("utf-8").
REPL Inspect
from codecs import encode
help(encode)
Linked from
Related notes
- tuts/python3/stdlib_module/codecs/backslashreplace_errors Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/Codec Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/CodecInfo Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/decode Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/EncodedFile Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/codecs/getdecoder shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getencoder shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getincrementaldecoder shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getincrementalencoder shared tags: #codecs, #stdlib