Message22525
Giving random.choice(seq) an empty sequence leads to a
misleading error message, as per this example:
>>> import random; random.choice([])
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.3/random.py", line 231, in choice
return seq[int(self.random() * len(seq))]
IndexError: list index out of range
A simple fix is to "assert len(seq) > 0" in the choice
method. |
|
Date |
User |
Action |
Args |
2007-08-23 14:26:24 | admin | link | issue1033038 messages |
2007-08-23 14:26:24 | admin | create | |
|