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
48eca67a
Kaydet (Commit)
48eca67a
authored
Ara 14, 2007
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add line spacing for readability
üst
a63f2683
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
collections.rst
Doc/library/collections.rst
+8
-1
collections.py
Lib/collections.py
+8
-8
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
48eca67a
...
...
@@ -385,18 +385,25 @@ Example::
>>> Point = namedtuple('Point', 'x y', verbose=True)
class Point(tuple):
'Point(x, y)'
__slots__ = ()
_fields = ('x', 'y')
def __new__(cls, x, y):
return tuple.__new__(cls, (x, y))
def __repr__(self):
return 'Point(x=%r, y=%r)' % self
def _asdict(self):
'Return a new dict
mapping
field names to their values'
'Return a new dict
which maps
field names to their values'
return dict(zip(('x', 'y'), self))
def _replace(self, **kwds):
'Return a new Point object replacing specified fields with new values'
return Point(**dict(zip(('x', 'y'), self), **kwds))
x = property(itemgetter(0))
y = property(itemgetter(1))
...
...
Lib/collections.py
Dosyayı görüntüle @
48eca67a
...
...
@@ -59,19 +59,19 @@ def namedtuple(typename, field_names, verbose=False):
argtxt
=
repr
(
field_names
)
.
replace
(
"'"
,
""
)[
1
:
-
1
]
# tuple repr without parens or quotes
reprtxt
=
', '
.
join
(
'
%
s=
%%
r'
%
name
for
name
in
field_names
)
template
=
'''class
%(typename)
s(tuple):
'
%(typename)
s(
%(argtxt)
s)'
__slots__ = ()
_fields = property(lambda self:
%(field_names)
r)
'
%(typename)
s(
%(argtxt)
s)'
\n
__slots__ = ()
\n
_fields = property(lambda self:
%(field_names)
r)
\n
def __new__(cls,
%(argtxt)
s):
return tuple.__new__(cls, (
%(argtxt)
s))
return tuple.__new__(cls, (
%(argtxt)
s))
\n
def __repr__(self):
return '
%(typename)
s(
%(reprtxt)
s)'
%%
self
return '
%(typename)
s(
%(reprtxt)
s)'
%%
self
\n
def _asdict(self, dict=dict, zip=zip):
'Return a new dict
mapping
field names to their values'
return dict(zip(
%(field_names)
r, self))
'Return a new dict
which maps
field names to their values'
return dict(zip(
%(field_names)
r, self))
\n
def _replace(self, **kwds):
'Return a new
%(typename)
s object replacing specified fields with new values'
return
%(typename)
s(**dict(zip(
%(field_names)
r, self), **kwds))
\n
'''
%
locals
()
return
%(typename)
s(**dict(zip(
%(field_names)
r, self), **kwds))
\n
\n
'''
%
locals
()
for
i
,
name
in
enumerate
(
field_names
):
template
+=
'
%
s = property(itemgetter(
%
d))
\n
'
%
(
name
,
i
)
if
verbose
:
...
...
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