如何使用sed/将其转换为Python



有没有把下面的给定行转换成Python的想法?

sed 's+forwarding_link+'$link'+g' first.html > index2.html
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)

这可能对有用

由于link是一个变量,它将在Python 中保持原样

您必须读取文件first.html,使用string.replace替换匹配的字符串,然后将结果转储到index2.html中。

link = 'your link here'
with open('first.html') as infile:
data = infile.read()
data = data.replace('forwarding_link', link)
with open('index2.html', 'w') as outfile:
outfile.write(data)

相关内容

  • 没有找到相关文章

最新更新