iterating over result sets in python
I am trying to iterate over a result set from a zsql method in a python script in Zope 2. In the results is a date field. What I want to do is test whether a date is younger than the date in the previous row by at least 30 days but I am having problems working out how, not coming from a pythonic background. Could anyone point me in the correct direction? Regards garry
That's easy. prev_date = None for record in recordset: if prev_date is None: prev_date = record.mydate print "first date: %s" % record.mydate elif (prev_date + 30) > record.mydate: print "%s days since previous date" % (record.mydate - prev_date) 2008/8/24 Garry Saddington <garry@schoolteachers.co.uk>:
I am trying to iterate over a result set from a zsql method in a python script in Zope 2. In the results is a date field. What I want to do is test whether a date is younger than the date in the previous row by at least 30 days but I am having problems working out how, not coming from a pythonic background. Could anyone point me in the correct direction? Regards garry _______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com
participants (2)
-
Garry Saddington -
Peter Bengtsson