https://docs.python.org/3.7/library/io.html#text-i-o says that io.Stringio is created inside of an open() file object. If I want to start with a Stringio and then flush it into a file object how would I do that? Obviously I could just open the new file object and then write the Stringio to the object, but is there a cleaner way?
from io import *
buf = StringIO()
buf.write('here is my text in stringio')
buf.flush('filename')
buf.close()
Other than
buf = StringIO()
buf.write('here is my text in stringio')
with open('filename', 'w') as fo:
buf.seek(0)
fo.write(buf.read())
buf.close()
is there a way to do this?