s.write('GH') .net
print s.read() 指針
# 將輸出abcDEFGH 對象
print s.getvalue() blog
經過例子,咱們看到了StringIO的行爲,基本與file一致。StringIO提供了一個方法,能夠方便的獲取其中的數據:StringIO. getvalue()。若是使用read方法獲取其中的數據,必須經過seek先設置"文件指針"的位置。get
轉載自:http://blog.csdn.net/piaoyidage/article/details/42098911it