【小代码】01-去除verilog工程的make_debug的python脚本

参考:

【Python库】05—RE正则表达式

【Python库】04—glob文件查找

import re
import glob
#读取整个文件
file = glob.iglob(r'.\src\*.v')
for i in file:
    with open(i,'r', encoding='utf-8') as f1:
        all_text = f1.read()
        new_text = re.sub(r'(\(\*mark_debug \= \"true\"\*\))|(\(\*MARK_DEBUG \= \"TRUE\"\*\))','',all_text)  
    f1.close()

    with open(i,'w', encoding='utf-8') as f2:
        f2.write(new_text)
    f2.close()

之前的代码,不支持遍历子目录的内容,先更新代码后,可以支持遍历子目录的内容。

import re
import glob
#读取整个文件
file = glob.iglob(r'**\*.v',recursive=True)
for i in file:
    with open(i,'r', encoding='utf-8') as f1:
        all_text = f1.read()
        new_text = re.sub(r'(\(\*mark_debug \= \"true\"\*\))|(\(\*MARK_DEBUG \= \"TRUE\"\*\))','',all_text)  
    f1.close()

    with open(i,'w', encoding='utf-8') as f2:
        f2.write(new_text)
    f2.close()

REF:

https://blog.youkuaiyun.com/jy692405180/article/details/52245829

https://docs.python.org/3/library/glob.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值