On Tue, Apr 29, 2008 at 11:11 AM, D'Arcy J.M. Cain <[EMAIL PROTECTED]> wrote:
> On Tue, 29 Apr 2008 09:33:32 -0500 > "Victor Subervi" <[EMAIL PROTECTED]> wrote: > > why doesn't this work? > > First, let me remove some blank lines to reduce scrolling. > > > z = 3 > > > > 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. > > > > z += 1 > > > > if z % 4 == 0: > > bg = '#ffffff' > > elif z % 4 == 1: > > bg = '#d2d2d2' > > elif z % 4 == 2: > > bg = '#F6E5DF' > > else: > > bg = '#EAF8D5' > > > > try: > > print '<tr bgcolor="%s">\n' % bg > > except: > > print '<tr>\n' > > > > It never increments z! Yet, if I print z, it will increment and change > the > > bgcolor! Why?! > > I am not entirely sure what you are trying to do here. First, what > error condition are you expecting in your try statement. Second, don't > you want the print clause, with or without the try/except, in the > loop. I assume that you want to print a line for each member of your > sequence in alternating colours but this only prints for the last one. > Try this: > > z = 3 > > for d in (1,2,3,4,5,6): > z += 1 > > if z % 4 == 0: > bg = '#ffffff' > elif z % 4 == 1: > bg = '#d2d2d2' > elif z % 4 == 2: > bg = '#F6E5DF' > else: > bg = '#EAF8D5' > > print '<tr bgcolor="%s">' % bg, d Huh? You´re asking for one variable, then giving two! How´s that work? > > > Or, tell us what you are trying to do. I think you understand. I want the row color to alternate, every fourth row color being the same (or a series of 4) > > > In fact, you can replace all the tests and the print statement with > this after defining bg as a list of the four colours: > > 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? TIA, Victor
-- http://mail.python.org/mailman/listinfo/python-list