如何用StringIO中的另一個替換字符串? - 如果它們的長度相同,我聽說它是可能的。 嘗試: from cStringIO import StringIO
c = 'can\nhaz\nfoo'
sio = StringIO(c)
for line in sio:
if line == 'haz\n':
# sio.write('bar\n')
StringIO在其代碼如下注意事項: Notes:
- Using a real file is often faster (but less convenient).
- There's also a much faster implementation in C, called cStringIO, but
it's not subclassable.
「真正的文件往往是快