Python的StringIO库用于实现在内存缓冲区读写文件,看官方对StringIO的介绍,第一句话就是:The module implements file-like class, StingIO, that reads and writes a string buffer(also known as memory files)
cStringIO和StringIO用法相同,速度更快,常常这样使用:
try:
import cStringIO as StringIO
except ImportError:
import StringIO
复制代码
>>> output = StringIO.StringIO()
>>> output.write('At that time, I was afraid')
>>> output