欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

路径替换小脚本

程序员文章站 2022-05-11 13:05:54
...

coding:utf8

# coding:utf8
import re

with open("./base.html", "r", encoding="utf-8") as f:
    lines = f.readlines()

with open("base1.html", "w", encoding="utf-8") as f_w:
    for line in lines:
        if re.search(r'"static/(.*?)"', line):
            replaceStr = re.search(r'"static/(.*?)"', line).groups()[0]  # 要插入的字符串
            a = re.sub(r'static/.*"', '{% static \'' + r'{0}'.format(replaceStr) + '\' %} " ', line)
            f_w.write(a)
            continue
        f_w.write(line)

路径替换小脚本

相关标签: 脚本