美文网首页JavaScript
【python前端小工具】:复制less/scss/stulys

【python前端小工具】:复制less/scss/stulys

作者: 剑指流云 | 来源:发表于2021-05-15 14:52 被阅读0次

    可自行修改文件路径和配置

    import re
    fileName = "course"
    with open(f'./src/less/{fileName}.less','r') as lines:
        text ="" 
        for line in lines:
            if(line and line.find("rpx")!=-1):
               hasRpxLine = re.findall("\d*",line)
               for rpx in hasRpxLine:
                   if(rpx):
                      num = int(rpx)
                      nowStr =  '{0}rpx'.format(rpx)
                      num =  round(100*num/750, 2)
                      currentStr = '{0}vw'.format(num)
                      line = line.replace(nowStr, currentStr)
            text = f'{text}{line}'
        print(text)
        with open (f'./src/less/{fileName}_copy.less','w') as file:
            file.write(text)
    
    

    windows中默认的编码方式是gbk,会报错,可设置打开方式为utf-8,或者删掉中文注释

    设置方式为encoding="UTF-8"

     open(f'./src/less/{fileName}.less','r',encoding="UTF-8")
    

    相关文章

      网友评论

        本文标题:【python前端小工具】:复制less/scss/stulys

        本文链接:https://www.haomeiwen.com/subject/gkqrjltx.html