gpt4 book ai didi

字符串的 Python 文件接口(interface)

转载 作者:太空狗 更新时间:2023-10-30 01:47:30 26 4
gpt4 key购买 nike

<分区>

是否有一个 Python 类将 file 接口(interface)(读、写等)包装在一个字符串周围?我的意思是类似于 C++ 中的 stringstream 类。

我正在考虑使用它来将 print 的输出重定向到一个字符串中,就像这样

sys.stdout = string_wrapper()
print "foo", "bar", "baz"
s = sys.stdout.to_string() #now s == "foo bar baz"

编辑:这是 How do I wrap a string in a file in Python? 的副本

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com