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
88a9164c
Kaydet (Commit)
88a9164c
authored
Mar 03, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Backport 70106: Add OrderedDict support to collections.namedtuple().
üst
bc512d3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
10 deletions
+16
-10
collections.rst
Doc/library/collections.rst
+9
-5
collections.py
Lib/collections.py
+5
-5
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
88a9164c
...
...
@@ -676,9 +676,9 @@ Example:
def __repr__(self):
return 'Point(x=%r, y=%r)' % self
<BLANKLINE>
def _asdict(
t
):
'Return a new
d
ict which maps field names to their values'
return
{'x': t[0], 'y': t[1]}
def _asdict(
self
):
'Return a new
OrderedD
ict which maps field names to their values'
return
OrderedDict(zip(self._fields, self))
<BLANKLINE>
def _replace(self, **kwds):
'Return a new Point object replacing specified fields with new values'
...
...
@@ -736,10 +736,14 @@ field names, the method and attribute names start with an underscore.
.. method:: somenamedtuple._asdict()
Return a new dict which maps field names to their corresponding values::
Return a new :class:`OrderedDict` which maps field names to their corresponding
values::
>>> p._asdict()
{'x': 11, 'y': 22}
OrderedDict([('x', 11), ('y', 22)])
.. versionchanged 3.1
Returns an :class:`OrderedDict` instead of a regular :class:`dict`.
.. method:: somenamedtuple._replace(kwargs)
...
...
Lib/collections.py
Dosyayı görüntüle @
88a9164c
...
...
@@ -164,7 +164,6 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
numfields
=
len
(
field_names
)
argtxt
=
repr
(
field_names
)
.
replace
(
"'"
,
""
)[
1
:
-
1
]
# tuple repr without parens or quotes
reprtxt
=
', '
.
join
(
'
%
s=
%%
r'
%
name
for
name
in
field_names
)
dicttxt
=
', '
.
join
(
'
%
r: t[
%
d]'
%
(
name
,
pos
)
for
pos
,
name
in
enumerate
(
field_names
))
template
=
'''class
%(typename)
s(tuple):
'
%(typename)
s(
%(argtxt)
s)'
\n
__slots__ = ()
\n
...
...
@@ -180,9 +179,9 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
return result
\n
def __repr__(self):
return '
%(typename)
s(
%(reprtxt)
s)'
%%
self
\n
def _asdict(
t
):
'Return a new
d
ict which maps field names to their values'
return
{
%(dicttxt)
s}
\n
def _asdict(
self
):
'Return a new
OrderedD
ict which maps field names to their values'
return
OrderedDict(zip(self._fields, self))
\n
def _replace(self, **kwds):
'Return a new
%(typename)
s object replacing specified fields with new values'
result = self._make(map(kwds.pop,
%(field_names)
r, self))
...
...
@@ -198,7 +197,8 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
# Execute the template string in a temporary namespace and
# support tracing utilities by setting a value for frame.f_globals['__name__']
namespace
=
dict
(
itemgetter
=
_itemgetter
,
__name__
=
'namedtuple_
%
s'
%
typename
)
namespace
=
dict
(
itemgetter
=
_itemgetter
,
__name__
=
'namedtuple_
%
s'
%
typename
,
OrderedDict
=
OrderedDict
)
try
:
exec
template
in
namespace
except
SyntaxError
,
e
:
...
...
Misc/NEWS
Dosyayı görüntüle @
88a9164c
...
...
@@ -170,6 +170,8 @@ Library
- PEP 372: Added collections.OrderedDict().
- The _asdict() for method for namedtuples now returns an OrderedDict().
- Issue #4308: httplib.IncompleteRead's repr doesn't include all of the data all
ready received.
...
...
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