【发布时间】:2019-06-17 07:32:41
【问题描述】:
我使用re 在文件中查找单词并将其存储为lattice_type
现在我想使用存储在lattice_type 上的单词来制作另一个正则表达式
我试过用这种方式使用变量名
pnt_grp=re.match(r'+ lattice_type + (.*?) .*',line, re.M|re.I)
在这里我查找正则表达式lattice_type= 并将group(1) 存储在lattice_type 中
latt=open(cell_file,"r")
for types in latt:
line = types
latt_type = re.match(r'lattice_type = (.*)', line, re.M|re.I)
if latt_type:
lattice_type=latt_type.group(1)
这是我想使用包含单词的变量在另一个文件中找到它的地方,但我遇到了问题
pg=open(parameters,"r")
for lines in pg:
line=lines
pnt_grp=re.match(r'+ lattice_type + (.*?) .*',line, re.M|re.I)
if pnt_grp:
print(pnt_grp(1))
【问题讨论】: