# 4.5 `StringIO` -- Read and write strings as files

This module implements a file-like class, `StringIO`, that reads and writes a string buffer (also known as memory files). See the description on file objects for operations (section ).

`StringIO` ([buffer])
  When a `StringIO` object is created, it can be initialized to an existing string by passing the string to the constructor. If no string is given, the `StringIO` will start empty.

The following methods of `StringIO` objects require special mention:

`getvalue` ()
  Retrieve the entire contents of the ``file'' at any time before the `StringIO` object's `close()` method is called.

`close` ()
  Free the memory buffer.