Return None if there's nothing in the database.

This commit is contained in:
Jeremy Fincher 2004-10-01 21:25:26 +00:00
parent 26771923f6
commit e3c9464634
1 changed files with 4 additions and 1 deletions

View File

@ -309,7 +309,10 @@ class DB(object):
def random(self):
# XXX This can be optimized not to deserialize each record.
return random.choice(self)
try:
return random.choice(self)
except IndexError:
return None
def size(self):
# XXX Likewise as above.