On this page
io.IncrementalNewlineDecoder
Prev: io.FileIO | Up: io | Next: io.IOBase
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.IncrementalNewlineDecoder
Tags: #public #python3 #stdlib #io
Import
import io
from io import IncrementalNewlineDecoder
Signature & Overview
io.IncrementalNewlineDecoder(decoder, translate, errors='strict')
Codec used when reading a file in universal newlines mode.
Methods & Attributes
IncrementalNewlineDecoder.decode(self, /, input, final=False)—IncrementalNewlineDecoder.decodemethod/property.IncrementalNewlineDecoder.getstate(self, /)—IncrementalNewlineDecoder.getstatemethod/property.IncrementalNewlineDecoder.reset(self, /)—IncrementalNewlineDecoder.resetmethod/property.IncrementalNewlineDecoder.setstate(self, state, /)—IncrementalNewlineDecoder.setstatemethod/property.
Usage
import codecs
import io
dec = io.IncrementalNewlineDecoder(codecs.getincrementaldecoder("utf-8")(), translate=True)
assert dec.decode(b"a\r\nb\rc", final=True) == "a\nb\nc"
assert set(dec.newlines) == {"\r\n", "\r"}
Gotchas
- Powers universal newlines in
TextIOWrapper: Translates\r\nand\rinto\neven when a\r\npair is split across two chunks.
REPL Inspect
from io import IncrementalNewlineDecoder
help(IncrementalNewlineDecoder)
Linked from
Related notes
- tuts/python3/stdlib_module/io/FileIO Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/IOBase Linked here; links to this page; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/io/BlockingIOError Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedIOBase Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedRandom Linked here; shared tags: #io, #stdlib
- tuts/python3/stdlib_module/io/BufferedReader Linked here; shared tags: #io, #stdlib
- tuts/c/stdlib/stdio_and_file_io shared tags: #io, #stdlib
- tuts/cpp/stdlib/io_and_filesystem shared tags: #io, #stdlib
- tuts/cpp/stdlib/io_and_filesystem/format_and_print shared tags: #io, #stdlib