Re: [Cheetahtemplate-discuss] "Alt" table rows
Brought to you by:
rtyler,
tavis_rudd
From: Mike O. <ms...@oz...> - 2003-05-14 20:30:31
|
On Wed, May 14, 2003 at 09:04:12PM +0200, deelan wrote: > Mike Orr wrote: > >On Wed, May 14, 2003 at 12:46:14PM -0400, Aaron Held wrote: > > > >>The trick that I use is to setup > >> > >>#for $z in range(0,len($data)) > >><tr class="dataRow#echo $z%2#" > > is there a missing ">" at the end of the line or was it > intentional? It's prob'ly missing. > >If you're doing a traditional table with one row per record: > > > >#for $i, $row in $zip( $range($len($data)), $data ) > > ouch, this will took me a while to decrypt (i'm a python newbie), > let me guess: with range() i build a list from zero to "lenght > of list", the zip() function map each range index to each > value in $data list (my db recordset) so now i have a list of > couples (index, value), the #for will loop thru such list mapping > $i with the index, $row with the value. i imagine i'll then use $i in > that echo line: > > <tr class="dataRow#echo $i%2#"> > > correct? Yes. The traditional Python ways to do this before zip() were: for i in range(len(data)): row = data[i] ... bla bla bla ... i = 0 for row in data: ... bla bla bla ... i += 1 But translating these to Cheetah would require an ugly number of #set's. The best way to do this might be to define your own enumerate() function until Python 2.3 is stable. === try: enumerate except NameError: def enumerate(data): ret = [] for i in range(len(data)): elem = data[i] tup = i, elem ret.append(tup) return ret === #from MyLibrary import enumerate Of course you could save memory by using generators, but I wanted to keep the example simple and have it work under all versions of Python. > do u recommend python 2.3 for commercial products? is it > stable enough? i'm using 2.2 for my initial experiements. I haven't been hit by any new bugs in 2.3. For products that will be out the door before this fall, use 2.2. For products that will be out the door later, you can use 2.3 provided: - You have a backup plan to drop to 2.2 if you come across inconvenient bugs or the 2.3 target date (July 4) slips. - Don't do it if grumbly bosses or impatient coworkers would make a fuss if something goes wrong. Two problems I've had with 2.2.2 and 2.3a0 is PIL and MySQLdb won't build; they complain about a missing .c or .h file. It's probably my environment's fault rather than Python's fault. I've tried to install all the library packages and development packages but something is still missing. Unittests are a big help. That's what we use for Cheetah. Before checking in any changes, we run the test suite. Before making a release, we test it under all versions of Python we say we support in case any version-specific problems have crept in. Testing against a different version of Python is a simple matter of running the top-level script with the alternate interpreter: cd ~/Cheetah /path/to/python-VERSION setup.py install /path/to/python-VERSION /path/to/python-VERSION/bin/cheetah test -- -Mike (Iron) Orr, ms...@oz... (ir...@se...) English * Esperanto * Russkiy * Deutsch * Espan~ol |