Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
449a87d7
Kaydet (Commit)
449a87d7
authored
Ara 11, 2002
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Various additions and changes suggested by Raymond Hettinger
üst
da9f853b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
16 deletions
+85
-16
whatsnew23.tex
Doc/whatsnew/whatsnew23.tex
+85
-16
No files found.
Doc/whatsnew/whatsnew23.tex
Dosyayı görüntüle @
449a87d7
...
...
@@ -833,6 +833,16 @@ creates a dictionary with keys taken from the supplied iterator
(Patches contributed by Raymond Hettinger.)
The dict() constructor now also accepts keyword arguments to simplify
creating small dictionaries:
\begin{verbatim}
>>> dict(red=1, blue=2, green=3, black=4)
{
'blue': 2, 'black': 4, 'green': 3, 'red': 1
}
\end{verbatim}
(Contributed by Just van Rossum.)
\item
The
\keyword
{
assert
}
statement no longer checks the
\code
{__
debug
__}
flag, so you can no longer disable assertions by assigning to
\code
{__
debug
__}
.
Running Python with the
\programopt
{
-O
}
switch will still generate
...
...
@@ -1014,6 +1024,10 @@ and significantly reworked by Tim Peters.)
small speed increase, subject to your compiler's idiosyncrasies.
(Removed by Michael Hudson.)
\item
\function
{
xrange()
}
objects now have their own iterator, making
\code
{
for i in xrange(n)
}
slightly faster than
\code
{
for i in range(n)
}
. (Patch by Raymond Hettinger.)
\item
A number of small rearrangements have been made in various
hotspots to improve performance, inlining a function here, removing
some code there. (Implemented mostly by GvR, but lots of people have
...
...
@@ -1177,28 +1191,30 @@ will enable buffering.
\item
The
\function
{
sample(
\var
{
population
}
,
\var
{
k
}
)
}
function was
added to the
\module
{
random
}
module.
\var
{
population
}
is a sequence
containing the elements of a population, and
\function
{
sample()
}
or
\code
{
xrange
}
object
containing the elements of a population, and
\function
{
sample()
}
chooses
\var
{
k
}
elements from the population without replacing chosen
elements.
\var
{
k
}
can be any value up to
\code
{
len(
\var
{
population
}
)
}
.
For example:
\begin{verbatim}
>>> pop = range(6) ; pop
[0, 1, 2, 3, 4, 5]
>>> random.sample(pop, 3) # Choose three elements
[0, 4, 3]
>>> random.sample(pop, 6) # Choose all six elements
[4, 5, 0, 3, 2, 1]
>>> random.sample(pop, 6) # Choose six again
[4, 2, 3, 0, 5, 1]
>>> random.sample(pop, 7) # Can't choose more than six
>>> days = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'St', 'Sn']
>>> random.sample(days, 3) # Choose 3 elements
['St', 'Sn', 'Th']
>>> random.sample(days, 7) # Choose 7 elements
['Tu', 'Th', 'Mo', 'We', 'St', 'Fr', 'Sn']
>>> random.sample(days, 7) # Choose 7 again
['We', 'Mo', 'Sn', 'Fr', 'Tu', 'St', 'Th']
>>> random.sample(days, 8) # Can't choose eight
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "random.py", line
396
, in sample
raise ValueError, "sample larger than population"
File "random.py", line
414
, in sample
raise ValueError, "sample larger than population"
ValueError: sample larger than population
>>>
>>> random.sample(xrange(1,10000,2), 10) # Choose ten odds under 10000
[3407, 3805, 1505, 7023, 2401, 2267, 9733, 3151, 8083, 9195]
\end{verbatim}
(Contributed by Raymond Hettinger.)
\item
The
\module
{
readline
}
module also gained a number of new
functions:
\function
{
get
_
history
_
item()
}
,
...
...
@@ -1270,6 +1286,58 @@ sometimes have odd bugs. Brett Cannon contributed a portable
implementation that's written in pure Python, which should behave
identically on all platforms.
\item
The
\module
{
UserDict) has a new
\class
{
DictMixin
}
class which
defines all dictionary methods for classes that already have a minimum
mapping interface. This greatly simplifies writing classes that need
to be substitutable for dictionaries, such as the classes in
the
\module
{
shelve
}
module.
Adding the mixin as a superclass provides the full dictionary
interface whenever the class defines
\method
{__
getitem
__}
,
\method
{__
setitem
__}
,
\method
{__
delitem
__
), and
\method
{
keys
}
.
For example:
\begin{verbatim}
>>> import UserDict
>>> class SeqDict(UserDict.DictMixin):
"""Dictionary lookalike implemented with lists."""
def
__
init
__
(self):
self.keylist = []
self.valuelist = []
def
__
getitem
__
(self, key):
try:
i = self.keylist.index(key)
except ValueError:
raise KeyError
return self.valuelist[i]
def
__
setitem
__
(self, key, value):
try:
i = self.keylist.index(key)
self.valuelist[i] = value
except ValueError:
self.keylist.append(key)
self.valuelist.append(value)
def
__
delitem
__
(self, key):
try:
i = self.keylist.index(key)
except ValueError:
raise KeyError
self.keylist.pop(i)
self.valuelist.pop(i)
def keys(self):
return list(self.keylist)
>>> s = SeqDict()
>>> dir(s) # See that other dictionary methods are implemented
['
__
cmp
__
', '
__
contains
__
', '
__
delitem
__
', '
__
doc
__
', '
__
getitem
__
',
'
__
init
__
', '
__
iter
__
', '
__
len
__
', '
__
module
__
', '
__
repr
__
',
'
__
setitem
__
', 'clear', 'get', 'has
_
key', 'items', 'iteritems',
'iterkeys', 'itervalues', 'keylist', 'keys', 'pop', 'popitem',
'setdefault', 'update', 'valuelist', 'values']
\end
{
verbatim
}
(Contributed by Raymond Hettinger.)
\item
The DOM implementation
in
\module
{
xml.dom.minidom
}
can now generate XML output in a
particular encoding, by specifying an optional encoding argument to
...
...
@@ -1711,8 +1779,9 @@ name.
The author would like to thank the following people for offering
suggestions, corrections and assistance with various drafts of this
article: Simon Brunning, Michael Chermside, Scott David Daniels,
Fred~L. Drake, Jr., Michael Hudson, Detlef Lannert, Martin von
L
\"
owis, Andrew MacIntyre, Lalo Martins, Gustavo Niemeyer, Neal
Norwitz, Chris Reedy, Vinay Sajip, Neil Schemenauer, Jason Tishler.
Fred~L. Drake, Jr., Raymond Hettinger, Michael Hudson, Detlef Lannert,
Martin von L
\"
owis, Andrew MacIntyre, Lalo Martins, Gustavo Niemeyer,
Neal Norwitz, Chris Reedy, Vinay Sajip, Neil Schemenauer, Jason
Tishler.
\end
{
document
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment