小编pse*_*ine的帖子

使用 Python 将多行字符串写入文本文件

我正在尝试将字符串的多行写入 Python3 中的文本文件,但它只写入单行。

例如

假设打印我的字符串会在控制台中返回该字符串;

>> print(mylongstring)
https://www.link1.com
https://www.link2.com
https://www.link3.com
https://www.link4.com
https://www.link5.com
https://www.link6.com
Run Code Online (Sandbox Code Playgroud)

我将其写入文本文件

f = open("temporary.txt","w+")
f.write(mylongstring)
Run Code Online (Sandbox Code Playgroud)

我的文本文件中读取的所有内容都是第一个链接(link1.com)

有什么帮助吗?如果您愿意,我可以详细说明,毕竟这是我的第一篇文章。

python python-3.x

7
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

python-3.x ×1