Rows.find(f,limitby=(0,10))

This commit is contained in:
mdipierro
2012-08-30 20:07:34 -05:00
parent 1cf2f84d24
commit 79e7d974ad
2 changed files with 12 additions and 6 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.0.3 (2012-08-30 17:36:15) stable Version 2.0.3 (2012-08-30 20:07:31) stable
+11 -5
View File
@@ -8946,18 +8946,24 @@ class Rows(object):
return None return None
return self[-1] return self[-1]
def find(self,f): def find(self,f,limitby=None):
""" """
returns a new Rows object, a subset of the original object, returns a new Rows object, a subset of the original object,
filtered by the function f filtered by the function f
""" """
if not self.records: if not self:
return Rows(self.db, [], self.colnames) return Rows(self.db, [], self.colnames)
records = [] records = []
for i in range(0,len(self)): if limitby:
row = self[i] a,b = limitby
else:
a,b = 0,len(self)
k = 0
for row in self:
if f(row): if f(row):
records.append(self.records[i]) if a<=k: records.append(row)
k += 1
if k==b: break
return Rows(self.db, records, self.colnames) return Rows(self.db, records, self.colnames)
def exclude(self, f): def exclude(self, f):