On this page
codecs.IncrementalEncoder
Prev: codecs.IncrementalDecoder | Up: codecs | Next: codecs.iterdecode
Rel: codecs.backslashreplace_errors, codecs.Codec, codecs.CodecInfo, codecs.decode
Ref: docs.python.org — codecs.IncrementalEncoder
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import IncrementalEncoder
Signature & Overview
codecs.IncrementalEncoder(errors='strict')
An IncrementalEncoder encodes an input in multiple steps. The input can be passed piece by piece to the encode() method. The IncrementalEncoder remembers the state of the encoding process between calls to encode().
Methods & Attributes
IncrementalEncoder.encode(self, input, final=False)— Encodes input and returns the resulting object.IncrementalEncoder.getstate(self)— Return the current state of the encoder.IncrementalEncoder.reset(self)— Resets the encoder to the initial state.IncrementalEncoder.setstate(self, state)— Set the current state of the encoder. state must have been returned by getstate().
Usage
import codecs
enc = codecs.getincrementalencoder("utf-16")()
out = enc.encode("a", final=False) + enc.encode("b", final=True)
assert out.decode("utf-16") == "ab"
Gotchas
- Emits BOM once across chunks: Unlike calling
str.encode("utf-16")per chunk (which repeats the BOM).
REPL Inspect
from codecs import IncrementalEncoder
help(IncrementalEncoder)
Linked from
Related notes
- tuts/python3/stdlib_module/codecs/IncrementalDecoder Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/iterdecode 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/backslashreplace_errors Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/Codec Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/CodecInfo Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/decode Linked here; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/encode shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/EncodedFile shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getdecoder shared tags: #codecs, #stdlib