import StringIO as SIO s1 = "Hello" print id(s1) s2 = "Hello" + s1 print id(s2) sp = SIO.StringIO() sp.write("Hello") print sp.getvalue() print id(sp) sp.write("Leon") print sp.getvalue() print id(sp) exit()
主要进行字符串数据缓存,以便循环利用