]> granicus.if.org Git - python/commitdiff
SF bug #964230: random.choice([]) should return more intelligible exception
authorRaymond Hettinger <python@rcn.com>
Sat, 5 Jun 2004 14:53:22 +0000 (14:53 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 5 Jun 2004 14:53:22 +0000 (14:53 +0000)
Add a comment to make the traceback less mysterious.

Lib/random.py

index 58865fc59b973284387f439436bc0e93362531cf..92163bb608427ff472948c7cc20b17296779e31a 100644 (file)
@@ -237,7 +237,7 @@ class Random(_random.Random):
 
     def choice(self, seq):
         """Choose a random element from a non-empty sequence."""
-        return seq[int(self.random() * len(seq))]
+        return seq[int(self.random() * len(seq))]  # raises IndexError in seq is empty
 
     def shuffle(self, x, random=None, int=int):
         """x, random=random.random -> shuffle list x in place; return None.