gpt4 book ai didi

python - 如何在python3中读取多行字符串作为文件流?

转载 作者:太空宇宙 更新时间:2023-11-03 23:56:35 24 4
gpt4 key购买 nike

<分区>

我们如何在 python 中读取多行字符串作为文件流?

我试过这个:

import io

mystr = """
# comment line
line 1
line 2
line 3
"""

myfile = io.StringIO(mystr)

with open(myfile) as fi:
for line in fi.readlines():
print(line)

但这失败了。

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