Strange error message when calling random in Py1.5

Alex cut_me_out at hotmail.com
Sun May 7 21:06:20 EDT 2000


> >>> import random
> >>> random.random(100)
> Traceback (innermost last):
>    File "<pyshell#1>", line 1, in ?
> 	random.random(100)
> TypeError: too many arguments; expected 1, got 2
> >>> 
> 
> Whew.  This one's not believable.  Any ideas?

I think this is the reason:

>>> random.random
<method whrandom.random of whrandom instance at 104160>

...I always thought the fact that the "TypeError: too many arguments"
error is off by one for bound methods was very misleading.  It confused
the hell out of me one afternoon...

It seems as if random.random is not meant to take any arguments, and
returns a random float between 0 and 1:

>>> random.random()
0.755391751557

Alex.



More information about the Python-list mailing list