[ python-Bugs-964230 ] random.choice([]) should return more intelligible exception

SourceForge.net noreply at sourceforge.net
Sat Jun 5 01:39:03 EDT 2004


Bugs item #964230, was opened at 2004-06-01 07:39
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=964230&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Hoffman (hoffmanm)
Assigned to: Nobody/Anonymous (nobody)
Summary: random.choice([]) should return more intelligible exception

Initial Comment:
Python 2.3.3 (#1, Mar 31 2004, 11:17:07)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> 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

This is simple enough here, but it's harder when it's
at the bottom of a traceback.

I suggest something like ValueError: sequence must not
be empty.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-06-05 00:39

Message:
Logged In: YES 
user_id=80475

-0

While a ValueError would be appropriate, the status quo
doesn't bug me much and changing it could break code if
someone is currently trapping the IndexError.  



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=964230&group_id=5470



More information about the Python-bugs-list mailing list