Allowing for direct iteration over rows in a table
This commit is contained in:
parent
7638e898fd
commit
258e3f3059
@ -231,6 +231,9 @@ class Table(object):
|
||||
yield row
|
||||
|
||||
def __len__(self):
|
||||
"""
|
||||
Returns the number of rows in the table.
|
||||
"""
|
||||
d = self.database.query(self.table.count()).next()
|
||||
return d.values().pop()
|
||||
|
||||
@ -268,3 +271,14 @@ class Table(object):
|
||||
|
||||
rows = table.all()"""
|
||||
return self.find()
|
||||
|
||||
def __iter__(self):
|
||||
"""
|
||||
Allows for iterating over all rows in the table without explicelty calling :py:meth:`all() <dataset.Table.all>`.
|
||||
::
|
||||
|
||||
for row in table:
|
||||
print row
|
||||
"""
|
||||
for row in self.all():
|
||||
yield row
|
||||
|
||||
Loading…
Reference in New Issue
Block a user