Custom Search

Wednesday, March 9, 2016

python StringIO read and write strings as files

>>>from cStringIO import StringIO

>>>buf=StringIO()

>>>def write_to_buffer(buf):
            for i in range(1,10):
                buf.write(str(i))


>>>buf.getvalue()

>>>write_to_buffer(buf)

>>>buf.getvalue()


No comments:

Post a Comment