Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8a61f49

Browse files
committed
Fill out the 'Porting' section
Add random.sample()
1 parent e117258 commit 8a61f49

1 file changed

Lines changed: 62 additions & 2 deletions

File tree

Doc/whatsnew/whatsnew23.tex

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ \section{New and Improved Modules}
943943
\url{http://www.nist.gov/dads/HTML/priorityque.html} for more
944944
information about the priority queue data structure.)
945945

946-
The Python \module{heapq} module provides \function{heappush()} and
946+
The \module{heapq} module provides \function{heappush()} and
947947
\function{heappop()} functions for adding and removing items while
948948
maintaining the heap property on top of some other mutable Python
949949
sequence type. For example:
@@ -1000,6 +1000,31 @@ \section{New and Improved Modules}
10001000
the parser object's \member{buffer_text} attribute to \constant{True}
10011001
will enable buffering.
10021002

1003+
\item The \function{sample(\var{population}, \var{k})} function was
1004+
added to the \module{random} module. \var{population} is a sequence
1005+
containing the elements of a population, and \function{sample()}
1006+
chooses \var{k} elements from the population without replacing chosen
1007+
elements. \var{k} can be any value up to \code{len(\var{population})}.
1008+
For example:
1009+
1010+
\begin{verbatim}
1011+
>>> pop = range(6) ; pop
1012+
[0, 1, 2, 3, 4, 5]
1013+
>>> random.sample(pop, 3) # Choose three elements
1014+
[0, 4, 3]
1015+
>>> random.sample(pop, 6) # Choose all six elements
1016+
[4, 5, 0, 3, 2, 1]
1017+
>>> random.sample(pop, 6) # Choose six again
1018+
[4, 2, 3, 0, 5, 1]
1019+
>>> random.sample(pop, 7) # Can't choose more than six
1020+
Traceback (most recent call last):
1021+
File ``<stdin>'', line 1, in ?
1022+
File ``/home/amk/src/sf/python/dist/src/Lib/random.py'', line 396, in sample
1023+
raise ValueError, ``sample larger than population''
1024+
ValueError: sample larger than population
1025+
>>>
1026+
\end{verbatim}
1027+
10031028
\item The \module{readline} module also gained a number of new
10041029
functions: \function{get_history_item()},
10051030
\function{get_current_history_length()}, and \function{redisplay()}.
@@ -1338,7 +1363,42 @@ \section{Other Changes and Fixes}
13381363
%======================================================================
13391364
\section{Porting to Python 2.3}
13401365

1341-
XXX write this
1366+
This section lists changes that may actually require changes to your code:
1367+
1368+
\begin{itemize}
1369+
1370+
\item \keyword{yield} is now always a keyword; if it's used as a
1371+
variable name in your code, a different name must be chosen.
1372+
1373+
\item You can no longer disable assertions by assigning to \code{__debug__}.
1374+
1375+
\item Using \code{None} as a variable name will now result in a
1376+
\exception{SyntaxWarning} warning.
1377+
1378+
\item Names of extension types defined by the modules included with
1379+
Python now contain the module and a \samp{.} in front of the type
1380+
name.
1381+
1382+
\item For strings \var{X} and \var{Y}, \code{\var{X} in \var{Y}} now works
1383+
if \var{X} is more than one character long.
1384+
1385+
\item The Distutils \function{setup()} function has gained various new
1386+
keyword arguments such as \samp{depends}. Old versions of the
1387+
Distutils will abort if passed unknown keywords. The fix is to check
1388+
for the presence of the new \function{get_distutil_options()} function
1389+
in your \file{setup.py} if you want to only support the new keywords
1390+
with a version of the Distutils that supports them:
1391+
1392+
\begin{verbatim}
1393+
from distutils import core
1394+
1395+
kw = {'sources': 'foo.c', ...}
1396+
if hasattr(core, 'get_distutil_options'):
1397+
kw['depends'] = ['foo.h']
1398+
ext = Extension(**kw)
1399+
\end{verbatim}
1400+
1401+
\end{itemize}
13421402

13431403

13441404
%======================================================================

0 commit comments

Comments
 (0)