gpt4 book ai didi

python - 将\n 替换为

转载 作者:IT老高 更新时间:2023-10-28 21:43:06 28 4
gpt4 key购买 nike

我正在使用 Python 解析文件中的文本。我必须用 <br /> 替换所有换行符.我试过这段代码:

thatLine.replace('\n', '<br />')
print thatLine

但我仍然看到后面带有换行符的文本。为什么?

最佳答案

thatLine = thatLine.replace('\n', '<br />')

str.replace() 返回字符串的副本,它不会修改你传入的字符串。

关于python - 将\n 替换为 <br/>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4369159/

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