In Python, how do I transform a string into a file?
Question: There is a read-only library function that takes a file as an argument. But I
have a string.

How do I convert a string to a file, that if you read the file it will return
this string? I don't want to write to disk.


Answer: The `StringIO` module:

    
    
    >>> import StringIO
    >>> f = StringIO.StringIO("foo")
    >>> f.read()
    'foo'
    

The `cStringIO` module has the same interface, and is faster, but can't deal
with Unicode strings that have non-ASCII characters.

[StringIO documentation](http://docs.python.org/library/stringio.html)

