StringIO.truncate()
StringIO.truncate() is a Python method in the IO Module category. Truncates the stream to the specified size. The syntax is StringIO.truncate(size=None). Parameters: size — new size. Returns: New size. A typical example: buf.truncate(0) # Clear the buffer. A close sibling is io.StringIO(), which creates an in-memory text stream (like a file for string I/O). 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. More about this category: Stream handling — StringIO, BytesIO for in-memory I/O. Related IO Module entries: io.StringIO(), io.BytesIO(), StringIO.getvalue(), StringIO.seek(), StringIO.close(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.