好的,所以我正在从我创建的字典(DoL)中读取一个变量:
for i in DoL.keys():
fobId = DoL["{}".format(i)]["FaceOuterBound"]
所以让我们说,在通过 DoL 的第一次迭代中:
fobId = 194
我试图创建一个包含变量的正则表达式 findall 表达式fobId
:
edgeloop_txt = re.findall(r'^#'+str(fobId)+r'.*#(\d+).*;', text)
为了找到text
以 # 开头的行fobId
:
#194 = FACE_OUTER_BOUND ( 'NONE', #159, .T. ) ;
最后提取数字#159
我的输出print(edgeloop_txt)
只是给了我空列表:
[]
[]
[]
...
编辑(提供 MCVE):
示例文本:
...
#190 = DIRECTION ( 'NONE', ( -1.000000000000000000, -0.0000000000000000000, -0.0000000000000000000 ) ) ;
#191 = DATE_AND_TIME ( #277, #349 ) ;
#192 = ORIENTED_EDGE ( 'NONE', *, *, #253, .T. ) ;
#193 = CARTESIAN_POINT ( 'NONE', ( 75.00000000000000000, 35.00000000000000000, 0.0000000000000000000 ) ) ;
#194 = FACE_OUTER_BOUND ( 'NONE', #159, .T. ) ;
#195 = ORIENTED_EDGE ( 'NONE', *, *, #205, .T. ) ;
#196 = CARTESIAN_POINT ( 'NONE', ( 0.0000000000000000000, 35.00000000000000000, 0.0000000000000000000 ) ) ;
...
我正在使用的代码:
for i in DoL.keys():
fobId = DoL["{}".format(i)]["FaceOuterBound"]
edgeloop_txt = re.findall(r'^#'+str(fobId)+r'.*#(\d+).*;', text)
print(edgeloop_txt)
DoL 是这样的字典:
{'Face0': {'AdvancedFace': 12, 'FaceOuterBound': 194, 'Plane': 326},
'Face1': {'AdvancedFace': 73, 'FaceOuterBound': 53, 'Plane': 230},
'Face2': {'AdvancedFace': 99, 'FaceOuterBound': 121, 'Plane': 123},
'Face3': {'AdvancedFace': 131, 'FaceOuterBound': 268, 'Plane': 270},
...
'Face9': {'AdvancedFace': 358, 'FaceOuterBound': 9, 'Plane': 363}}