【小代码】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.csdn.net/jy692405180/article/details/52245829

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

猜你喜欢

转载自blog.csdn.net/Neocst/article/details/81436550
01-