python中的StringIO模組
StringIO經常被用來作為字串的快取,應為StringIO有個好處,他的有些介面和檔案操作是一致的,也就是說用同樣的程式碼,可以同時當成檔案操作或者StringIO操作。
一、例子
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import StringIO s = StringIO.StringIO() s.write( 'www.baidu.com\r\n' ) s.write( 'news.realsil.com.cn' ) s.seek( 0 ) print '*' * 20 print s.tell()
|