Pattern “pll_dll_100m_test” { waveform_start: W pll_dll_100m_wft;
//Enter PLL/DLL Mode V {pll_dll_100m_group = 0 0 1 0 0 1 1 0 X X ;} V {pll_dll_100m_group = 0 1 1 0 0 1 1 0 X X ;} V {pll_dll_100m_group = 0 0 1 0 0 1 1 0 X X ;}
转后后:
//Enter PLL/DLL Mode V {pll_dll_100m_group = 0 0 1 0 0 1 1 0 X X ;} W pll_dll_100m_wft; V {pll_dll_100m_group = 0 1 1 0 0 1 1 0 X X ;}
infile_name = input("Please input the name of file in current directory to convert: ") name_flag = infile_name.find('.') if name_flag == -1: print("file name error, need input the suffix of file name") input("Please press Enter key to exit") exit(0) else: if os.path.isfile(infile_name): outfile_name = infile_name[0:name_flag] + "_updated" + infile_name[name_flag:] else: print("no such file!") input("Please press Enter key to exit") exit(0)
lines = infile.readlines() infile.close() flag = 0
for index inrange(len(lines)): str_obj = re.match('[\s]*W[\s].*', lines[index]) #match the "W ..." if str_obj != None: flag = 1 temp_index = index temp_str = str_obj.group() else: str_obj = re.match('[\s]*V[\s].*', lines[index]) #match the "V ..." if str_obj != None: if flag == 1: lines[temp_index] = '\n'#clear last "W ..." lines[index] = str_obj.group() + ' ' + temp_str + '\n'#add the "W ..." from "V ..." end flag = 0 outfile.writelines(lines) outfile.close() print("outputfile is " + outfile_name) input("Please press Enter key to exit")