#!/usr/bin/python
import os
lines=[]
path = os.getcwd()
def Add():
for foldName, subfolders, filenames in os.walk(path):
for filename in filenames:
if filename.endswith('.sv'):
with open(os.path.join(foldName,filename),"r") as f:
lines=f.readlins()
hit=0
for index,line in enumerate(lines):
if 'xxx' in line:
hit=index
if hit>0:
lines.insert(hit+2,' force top.xx.cc=1;\n') //force前空了4格,\n是独占一行
with open(os.path.join(foldName,filename),"w") as f:
for line in lines:
f.write(line)
Add()
print('ok!!!!')