This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author nejucomo
Recipients
Date 2004-09-22.23:48:38
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
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.
History
Date User Action Args
2007-08-23 14:26:24adminlinkissue1033038 messages
2007-08-23 14:26:24admincreate