io.StringIO()
io.StringIO() is a Python function in the IO Module category. Creates an in-memory text stream (like a file for string I/O). The syntax is io.StringIO(initial_value="", newline="\n"). Parameters: initial_value, newline. Returns: StringIO object. A typical example: from io import StringIO
buf = StringIO()
print("Hello", file=buf)
print("World", file=buf)
content = buf.getvalue() # "Hello\nWorld\n". A close sibling is io.BytesIO(), which creates an in-memory binary stream (like a file for bytes I/O). A close sibling is StringIO.getvalue(), which returns the entire contents of the StringIO buffer as a string. A close sibling is StringIO.seek(), which changes the stream position to the given offset. A close sibling is StringIO.truncate(), which truncates the stream to the specified size. More about this category: Stream handling — StringIO, BytesIO for in-memory I/O. Related IO Module entries: io.BytesIO(), StringIO.getvalue(), StringIO.seek(), StringIO.truncate(), StringIO.close(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.