/ Published in: Python
cStringIO -- Faster version of StringIO
Expand |
Embed | Plain Text
import cStringIO output = cStringIO.StringIO() output.write('First line.\n') print >>output, 'Second line.' # Retrieve file contents -- this will be # 'First line.\nSecond line.\n' contents = output.getvalue() # Close object and discard memory buffer -- # .getvalue() will now raise an exception. output.close()
You need to login to post a comment.
