On this page
codecs.Codec
Prev: codecs.backslashreplace_errors | Up: codecs | Next: codecs.CodecInfo
Rel: codecs.backslashreplace_errors, codecs.CodecInfo, codecs.decode, codecs.encode
Ref: docs.python.org โ codecs.Codec
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import Codec
Signature & Overview
codecs.Codec()
Defines the interface for stateless encoders/decoders.
Methods & Attributes
Codec.decode(self, input, errors='strict')โ Decodes the object input and returns a tuple (output object, length consumed).Codec.encode(self, input, errors='strict')โ Encodes the object input and returns a tuple (output object, length consumed).
Usage
import codecs
assert hasattr(codecs.Codec, "encode") and hasattr(codecs.Codec, "decode")
Gotchas
- Stateless codec base class: Subclass when implementing a custom encoding for
codecs.register().
REPL Inspect
from codecs import Codec
help(Codec)
Linked from
- tuts/python3/stdlib_module/codecs
- tuts/python3/stdlib_module/codecs/backslashreplace_errors
- tuts/python3/stdlib_module/codecs/CodecInfo
- tuts/python3/stdlib_module/codecs/decode
- tuts/python3/stdlib_module/codecs/encode
- tuts/python3/stdlib_module/codecs/EncodedFile
- tuts/python3/stdlib_module/codecs/getdecoder
- tuts/python3/stdlib_module/codecs/getencoder
- tuts/python3/stdlib_module/codecs/getincrementaldecoder
- tuts/python3/stdlib_module/codecs/getincrementalencoder
- tuts/python3/stdlib_module/codecs/getreader
- tuts/python3/stdlib_module/codecs/getwriter
- tuts/python3/stdlib_module/codecs/ignore_errors
- tuts/python3/stdlib_module/codecs/IncrementalDecoder
- tuts/python3/stdlib_module/codecs/IncrementalEncoder
- tuts/python3/stdlib_module/codecs/iterdecode
- tuts/python3/stdlib_module/codecs/iterencode
- tuts/python3/stdlib_module/codecs/lookup
- tuts/python3/stdlib_module/codecs/lookup_error
- tuts/python3/stdlib_module/codecs/namereplace_errors
- tuts/python3/stdlib_module/codecs/open
- tuts/python3/stdlib_module/codecs/register
- tuts/python3/stdlib_module/codecs/register_error
- tuts/python3/stdlib_module/codecs/replace_errors
- tuts/python3/stdlib_module/codecs/StreamReader
- tuts/python3/stdlib_module/codecs/StreamReaderWriter
- tuts/python3/stdlib_module/codecs/StreamRecoder
- tuts/python3/stdlib_module/codecs/StreamWriter
- tuts/python3/stdlib_module/codecs/strict_errors
- tuts/python3/stdlib_module/codecs/xmlcharrefreplace_errors
Related notes
- tuts/python3/stdlib_module/codecs/backslashreplace_errors 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/encode 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/EncodedFile links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getdecoder links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getencoder links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getincrementaldecoder links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getincrementalencoder links to this page; shared tags: #codecs, #stdlib