Colors for Rows

D'Arcy J.M. Cain darcy at druid.net
Tue Apr 29 15:31:08 EDT 2008


On Tue, 29 Apr 2008 13:14:34 -0500
"Victor Subervi" <victorsubervi at gmail.com> wrote:
> On Tue, Apr 29, 2008 at 11:11 AM, D'Arcy J.M. Cain <darcy at druid.net> wrote:
> > > for d in (1,2,3,4,5,6):
> >
> > I changed id to a sequence so that the example actually runs.  Please
> > run your examples first and cut and paste them into the message after
> > you are sure that it runs.
> 
> Not sure what you mean here. The example runs. It prints out <tr
> bgcolor="#ffffff"> every time.

No it doesn't.  Perhaps you had something that worked but you did not
include a definition of "id" in your code so it crashed right away.

> >  print '<tr bgcolor="%s">' % bg, d
> 
> Huh? You´re asking for one variable, then giving two! How´s that work?

No, I am asking print to display two items.  The first is "'<tr
bgcolor="%s">' % bg" and the second, following the comma, is "d" which
I simply added to show what iteration we were on.  I assume that you
would be printing some data from "id" in the real code and wrapping it
in <td> tags.

> I think you understand. I want the row color to alternate, every fourth row
> color being the same (or a series of 4)

Here is the output of the program I posted:

<tr bgcolor="#ffffff"> 1
<tr bgcolor="#d2d2d2"> 2
<tr bgcolor="#F6E5DF"> 3
<tr bgcolor="#EAF8D5"> 4
<tr bgcolor="#ffffff"> 5
<tr bgcolor="#d2d2d2"> 6

BTW, I am running Python 2.4.4.  You?

> >  print '<tr bgcolor="%s">' % bg[z % 4], d
> 
> I tried that just for fun. It gave a bg of ´f´. Again, how are you
> incorporating d?

Here is the complete script with the exact same output as above:

#! /usr/bin/env python
z = 3
bg = ('#ffffff', '#d2d2d2', '#F6E5DF', '#EAF8D5') 

for d in (1,2,3,4,5,6):
  z += 1
  print '<tr bgcolor="%s">' % bg[z % 4], d

-- 
D'Arcy J.M. Cain <darcy at druid.net>         |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



More information about the Python-list mailing list