Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping within a regex search
    primarykey
    data
    text
    <p>was wondering if I could get a little help with a bit of code I've produced shown here:</p> <pre><code>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") </code></pre> <p>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:</p> <pre><code>x=0 while x &lt; 1025: if re.search(r"\b", x, "ProcessorsRequested\b", output): corelist.append(x) break() x+=1 </code></pre> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload