math.choice attribute error

Brian Quinlan BrianQ at ActiveState.com
Mon Mar 26 22:20:50 EST 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 )
'apple'

Results should vary :-)

-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Sean 'Shaleh' Perry
Sent: Monday, March 26, 2001 5:44 PM
To: iddwb
Cc: python-list at python.org
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)
2

--
Brian Quinlan
Python and XSLT Developer
BrianQ at ActiveState.com

Use the power of the dragon for your programming needs.
Download Komodo, our Mozilla-based, cross-platform IDE.
      http://www.ActiveState.com/Komodo





More information about the Python-list mailing list