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

SourceForge.net noreply@sourceforge.net
Fri, 13 Jun 2003 01:50:25 -0700


Bugs item #753602, was opened at 2003-06-13 00:18
Message generated for change (Comment added) made by gerrit
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: Gerrit Holl (gerrit)
Date: 2003-06-13 10:50

Message:
Logged In: YES 
user_id=13298

Ah... thanks.

[Rest of comment offtopic]

Yes, Gerrit Holl is my real name. Gerrit is a quite
traditional Dutch name (we have a right-wing minister called
Gerrit and there is a song called "Ik ben Gerrit" (I am
Gerrit)) and Holl is a surname, I think it was originally
German... This is the first time this question was ever
asked to me :)

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-06-13 09: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-13 02: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