On this page
codecs.getwriter
Prev: codecs.getreader | Up: codecs | Next: codecs.ignore_errors
Rel: codecs.backslashreplace_errors, codecs.Codec, codecs.CodecInfo, codecs.decode
Ref: docs.python.org — codecs.getwriter
Tags: #public #python3 #stdlib #codecs
Import
import codecs
from codecs import getwriter
Signature & Overview
codecs.getwriter(encoding)
Lookup up the codec for the given encoding and return its StreamWriter class or factory function.
Usage
import codecs
import io
buf = io.BytesIO()
codecs.getwriter("utf-8")(buf).write("hello")
assert buf.getvalue() == b"hello"
Gotchas
- Prefer
io.TextIOWrapperfor standard text output.
REPL Inspect
from codecs import getwriter
help(getwriter)
Linked from
Related notes
- tuts/python3/stdlib_module/codecs/getreader Linked here; links to this page; shared tags: #codecs, #stdlib
- tuts/python3/stdlib_module/codecs/ignore_errors 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