Introducing StringIO : StringIO « String « Python Tutorial






import string

contents = "<grammar><ref id='bit'><para>0</para><para>1</para></ref></grammar>" 
import StringIO 
ssock = StringIO.StringIO(contents)          
print ssock.read()                                      
print ssock.read()                                     
print ssock.seek(0)                                      
print ssock.read(15)                                       
print ssock.read(15) 
print ssock.read() 
ssock.close()








5.33.StringIO
5.33.1.Introducing StringIO