【发布时间】:2020-03-20 10:47:57
【问题描述】:
import io
string_out = io.StringIO()
string_out.write("hello")
print(string_out.getvalue())
string_out.write("new Hello")
print(string_out.getvalue())
OutPut1: hello
OutPut2: hellonew Hello
我怎样才能从流中刷新我的第一个输入,以便第二个流的输出变成新的 Hello
【问题讨论】:
-
string_out.seek(0); string_out.truncate()会这样做