math.choice attribute error

Brian Quinlan BrianQ at
Tue Mar 27 05:20:50 CEST 2001

To be more explicit, the choice method does not live in the math module, it
lives in the random module. i.e.:

>>> import random
>>> list = ['apple', 'orange', 'pear']
>>> random.choice( list )

Results should vary :-)

-----Original Message-----
From: python-list-admin at
[mailto:python-list-admin at]On Behalf Of Sean 'Shaleh' Perry
Sent: Monday, March 26, 2001 5:44 PM
To: iddwb
Cc: python-list at
Subject: RE: math.choice attribute error

On 27-Mar-2001 iddwb wrote:
> from the ref man math.choice says it takes a sequence object and returns a
> random choice. perfect for my needs. the follow happens:
>>>> import math
>>>> list = ['apple', 'orange', 'pear']
>>>> print math.choice(list)
> Traceback ....
> attributerror: choice

I know random does:

>>> import random
>>> l = [1, 2, 3]
>>> random.choice(l)

Brian Quinlan
Python and XSLT Developer
BrianQ at

Use the power of the dragon for your programming needs.
Download Komodo, our Mozilla-based, cross-platform IDE.

More information about the Python-list mailing list