From e3c9464634dcb85eafdee3ebf154f55f3c4b302c Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Fri, 1 Oct 2004 21:25:26 +0000 Subject: [PATCH] Return None if there's nothing in the database. --- src/dbi.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/dbi.py b/src/dbi.py index 6275feed3..5715b5b70 100644 --- a/src/dbi.py +++ b/src/dbi.py @@ -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.