[ python-Bugs-1033038 ] Misleading error message in random.choice
SourceForge.net
noreply at sourceforge.net
Thu Sep 23 01:48:38 CEST 2004
Bugs item #1033038, was opened at 2004-09-22 23:48
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1033038&group_id=5470
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Nefarious CodeMonkey, Jr. (nejucomo)
Assigned to: Nobody/Anonymous (nobody)
Summary: Misleading error message in random.choice
Initial Comment:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1033038&group_id=5470
More information about the Python-bugs-list
mailing list