路径替换小脚本

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)

这里写图片描述

posted @ 2017-10-15 23:42  icanactnow  阅读(102)  评论(0编辑  收藏  举报