Note that there are some explanatory texts on larger screens.

plurals
  1. POPython: For loop problem
    text
    copied!<p>I have a PSP page with html embedded. I need to place another for loop so i can insert another %s next to <code>background-color:</code> which will instert a appropriate colour to colour in the html table.</p> <p>For example i need to insert <code>for z in colours</code> so it can loop over the colours list and insert the correct colour. Where ever i try to insert the for loop it doesnt seem to work it most commonly colours each cell in the table 60 times then moves onto the next cell and repeats itself and crashes my web browser.</p> <p>The colours are held in a table called colours.</p> <p>code below:</p> <pre><code>&lt;table&gt; &lt;% s = ''.join(aa[i] for i in table if i in aa) for i in range(0, len(s), 60): req.write('&lt;tr&gt;&lt;td&gt;&lt;TT&gt;%04d&lt;/td&gt;' % (i+1)); for k in s[i:i+60]: req.write('&lt;TT&gt;&lt;td&gt;&lt;TT&gt;&lt;font style="background-color:"&gt;%s&lt;font&gt;&lt;/td&gt;' % (k)); req.write('&lt;/TT&gt;&lt;/tr&gt;') #end %&gt; &lt;/table&gt; </code></pre> <p><strong>-----EDITED-----</strong></p> <p>Plugged in the code provided ebo, it colours the table all one colour. The colours list contains a variety of colours e.g. <code>colour = ['yellow', 'yellow', 'yellow', 'yellow', 'red', 'red', 'red', 'red']</code></p> <pre><code>&lt;table&gt; &lt;% s = ''.join(aa[i] for i in table if i in aa) for i in range(0, len(s), 60): req.write('&lt;tr&gt;&lt;td&gt;%04d&lt;/td&gt;' % (i+1)); for j, k in enumerate(s[i:i+60]): req.write('&lt;td&gt;&lt;font style="background-color:%s;"&gt;%s&lt;font&gt;&lt;/td&gt;' % (colour[j % len(colour)], k)); req.write('&lt;/tr&gt;') #end %&gt; &lt;/table&gt; </code></pre>
 

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