the other answers didn't work for me, but I managed to figure it out.
When using Python 3, you'll want to use io package.
import io
with io.StringIO("some initial text data") as f:
# now you can do things with f as if it was an opened file.
function_that_requires_a_Fileobject_as_argument(f)