was wondering if I could get a little help with a bit of code I’ve produced shown here:
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")
The problem with this code is obviously a lot of it’s repeated and also it means I can only search for a set list of cores (1,2,4 etc). How do I go about converting this code so it simply just loops from 1-1024? I thought it’d be something along the lines of this:
x=0
while x < 1025:
if re.search(r"\b", x, "ProcessorsRequested\b", output):
corelist.append(x)
break()
x+=1
But I think the syntax is wrong as it says (can’t remember exact wording) that I couldn’t pass more than 3 parameters in the regex part. Any help would be great! I hope I’ve made sense and if you need any more information then please ask.
Fix your regular expression to search for all of them, and tell you the number: