Posted By

freephys on 10/04/09


Tagged

String cStringIO


Versions (?)

cStringIO 1


 / Published in: Python
 

cStringIO -- Faster version of StringIO

  1. import cStringIO
  2.  
  3. output = cStringIO.StringIO()
  4. output.write('First line.\n')
  5. print >>output, 'Second line.'
  6.  
  7. # Retrieve file contents -- this will be
  8. # 'First line.\nSecond line.\n'
  9. contents = output.getvalue()
  10.  
  11. # Close object and discard memory buffer --
  12. # .getvalue() will now raise an exception.
  13. output.close()

Report this snippet  

You need to login to post a comment.