In the interest of not rewriting an open source library, I want to treat a string of text as a file in python 3.
Suppose I have the file contents as a stri
StringIO returns an StringIO
object, it's almost equivalent to the file object returned by the open
statement. So basically, you can use the StringIO in place of the open
statement.
# from io import StringIO for python 3
from StringIO import StringIO
with StringIO('there is a lot of blah blah in this so-called file') as f:
print(f.read())
Output:
there is a lot of blah blah in this so-called file