On this page
codecs.EncodedFile
Prev: codecs.encode | Up: codecs | Next: codecs.getdecoder
Rel: codecs.backslashreplace_errors, codecs.Codec, codecs.CodecInfo, codecs.decode
Ref: docs.python.org — codecs.EncodedFile
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import EncodedFile
Signature & Overview
codecs.EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
Return a wrapped version of file which provides transparent encoding translation.
Usage
import codecs
import io
raw = io.BytesIO("café".encode("latin-1"))
transcoded = codecs.EncodedFile(raw, data_encoding="utf-8", file_encoding="latin-1")
assert transcoded.read() == "café".encode("utf-8")
Gotchas
- Recodes binary streams on the fly: Usually clearer to decode with
TextIOWrapperand re-encode explicitly.
REPL Inspect
from codecs import EncodedFile
help(EncodedFile)
Linked from
Related notes
- tuts/python3/stdlib_module/codecs/encode Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/getdecoder 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/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