StringIO经常被用来作为字符串的缓存,应为StringIO有个好处,他的有些接口和文件操作是一致的,也就是说用同样的代码,可以同时当成文件操作或者StringIO操作。比如:
复制代码 代码如下:
import string, os, sys
import StringIO
def writedata(fd, msg):
fd.write(msg)
f = open('aaa.txt', 'w')
writedata(f, "xxxxxxxxxxxx")
f.close()
s = StringIO.StringIO()
writedata(s, "xxxxxxxxxxxxxx")
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8