On this page
  1. io.StringIO
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

io.StringIO

Prev: io.Reader | Up: io | Next: io.text_encoding
Rel: io.BlockingIOError, io.BufferedIOBase, io.BufferedRandom, io.BufferedReader
Ref: docs.python.org — io.StringIO
Tags: #public #python3 #stdlib #io


Import

import io
from io import StringIO

Signature & Overview

io.StringIO(initial_value='', newline='\n')

Text I/O implementation using an in-memory buffer.

Methods & Attributes

Usage

import io

buf = io.StringIO()
buf.write("line 1\n")
buf.write("line 2\n")
assert buf.getvalue() == "line 1\nline 2\n"

buf.seek(0)
assert buf.readline() == "line 1\n"

Gotchas

REPL Inspect

from io import StringIO
help(StringIO)

Linked from

Related notes