0
想知道内循环,如果我能得到了一些代码,我这里出产的显示一点帮助:正则表达式搜索
if re.search(r"\b2ProcessorsRequested\b", output):
corelist.append("2")
elif re.search(r"\b4ProcessorsRequested\b", output):
corelist.append("4")
elif re.search(r"\b8ProcessorsRequested\b", output):
corelist.append("8")
elif re.search(r"\b16ProcessorsRequested\b", output):
corelist.append("16")
elif re.search(r"\b32ProcessorsRequested\b", output):
corelist.append("32")
elif re.search(r"\b64ProcessorsRequested\b", output):
corelist.append("64")
elif re.search(r"\b128ProcessorsRequested\b", output):
corelist.append("128")
elif re.search(r"\b256ProcessorsRequested\b", output):
corelist.append("256")
elif re.search(r"\b512ProcessorsRequested\b", output):
corelist.append("512")
elif re.search(r"\b1024ProcessorsRequested\b", output):
corelist.append("1024")
else:
corelist.append("1")
这段代码的问题显然是一个很大的它的重复,也这意味着我只能搜索一组核心(1,2,4等)。我如何去转换这个代码,所以它只是从1-1024循环?我想那会沿着这个线的东西:
x=0
while x < 1025:
if re.search(r"\b", x, "ProcessorsRequested\b", output):
corelist.append(x)
break()
x+=1
但是我觉得语法是错误的,因为它说(不记得确切的措辞),我不能错过在超过3个参数正则表达式部分。任何帮助将是伟大的!我希望我有道理,如果你需要更多的信息,那么请问。
如果是这样'm.group(1)'? – mgilson