CKTIS / Python
Modulo io
Fornisce flussi grezzi, binari bufferizzati e testuali anche in memoria.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
io.TextIOWrapper(buffer, encoding="utf-8")Fornisce flussi grezzi, binari bufferizzati e testuali anche in memoria.
BytesIO gestisce byte e StringIO stringhe. TextIOWrapper codifica il testo per un flusso di byte, così quattro caratteri occupano qui cinque byte UTF-8.
Svuotare il buffer dell’involucro prima di esaminare i dati.
Esempi
import io
raw = io.BytesIO()
with io.TextIOWrapper(raw, encoding="utf-8", newline="") as text:
n = text.write("café")
text.flush()
print(n, len(raw.getvalue()), raw.getvalue().hex())
with io.StringIO("ab") as text:
print(text.read(1), text.read(), repr(text.read()))
Risultato
4 5 636166c3a9 a b ''
Svuotare il buffer dell’involucro prima di esaminare i dati.