[Python-bugs-list] [ python-Bugs-753602 ] random.sample not properly documented

SourceForge.net noreply@sourceforge.net
Fri, 13 Jun 2003 00:01:49 -0700


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

Category: Documentation
Group: Python 2.3
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Gerrit Holl (gerrit)
Assigned to: Raymond Hettinger (rhettinger)
Summary: random.sample not properly documented

Initial Comment:
random.sample seems to take a third argument:

 38 >>> random.sample(seq, 10, 'bla')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.3/random.py", line 247,
in sample
    j = int(random() * (n-i))
TypeError: 'str' object is not callable

However, the docs don't mention it.
I will try to patch it tomorrow (need to find out what
it does first ;)

Gerrit.

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-13 02:01

Message:
Logged In: YES 
user_id=80475

Moved the int() optimization out of the definition to prevent 
future misunderstandings.  See Lib/random.py 

BTW, is Gerritt Holl your real name?  Just curious.

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

Comment By: Tim Peters (tim_one)
Date: 2003-06-12 19:06

Message:
Logged In: YES 
user_id=31435

It's documented correctly.  The third argument is

int=int

and is simply a speed trick to avoid the expense of looking up 
the builtin name "int" in the function body every time the 
function is called.  Lots of speed-intensive functions do that, 
alas.  Since you're calling function with three arguments 
that's documented as taking two, your code is in error.

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

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