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
7b0d3c6d
Kaydet (Commit)
7b0d3c6d
authored
Nis 02, 2010
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add nice docstrings to namedtuples.
üst
41fe6155
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
collections.rst
Doc/library/collections.rst
+5
-2
collections.py
Lib/collections.py
+4
-1
No files found.
Doc/library/collections.rst
Dosyayı görüntüle @
7b0d3c6d
...
...
@@ -653,6 +653,7 @@ Example:
_fields = ('x', 'y')
<BLANKLINE>
def __new__(_cls, x, y):
'Create a new instance of Point(x, y)'
return _tuple.__new__(_cls, (x, y))
<BLANKLINE>
@classmethod
...
...
@@ -664,6 +665,7 @@ Example:
return result
<BLANKLINE>
def __repr__(self):
'Return a nicely formatted representation string'
return 'Point(x=%r, y=%r)' % self
<BLANKLINE>
def _asdict(self):
...
...
@@ -678,10 +680,11 @@ Example:
return result
<BLANKLINE>
def __getnewargs__(self):
'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
<BLANKLINE>
x = _property(_itemgetter(0))
y = _property(_itemgetter(1))
x = _property(_itemgetter(0)
, doc='Alias for field number 0'
)
y = _property(_itemgetter(1)
, doc='Alias for field number 1'
)
>>> p = Point(11, y=22) # instantiate with positional or keyword arguments
>>> p[0] + p[1] # indexable like the plain tuple (11, 22)
...
...
Lib/collections.py
Dosyayı görüntüle @
7b0d3c6d
...
...
@@ -233,6 +233,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
__slots__ = ()
\n
_fields =
%(field_names)
r
\n
def __new__(_cls,
%(argtxt)
s):
'Create new instance of
%(typename)
s(
%(argtxt)
s)'
return _tuple.__new__(_cls, (
%(argtxt)
s))
\n
@classmethod
def _make(cls, iterable, new=tuple.__new__, len=len):
...
...
@@ -242,6 +243,7 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
raise TypeError('Expected
%(numfields)
d arguments, got
%%
d'
%%
len(result))
return result
\n
def __repr__(self):
'Return a nicely formatted representation string'
return '
%(typename)
s(
%(reprtxt)
s)'
%%
self
\n
def _asdict(self):
'Return a new OrderedDict which maps field names to their values'
...
...
@@ -253,9 +255,10 @@ def namedtuple(typename, field_names, verbose=False, rename=False):
raise ValueError('Got unexpected field names:
%%
r'
%%
kwds.keys())
return result
\n
def __getnewargs__(self):
'Return self as a plain tuple. Used by copy and pickle.'
return tuple(self)
\n\n
'''
%
locals
()
for
i
,
name
in
enumerate
(
field_names
):
template
+=
'
%
s = _property(_itemgetter(
%
d))
\n
'
%
(
name
,
i
)
template
+=
"
%
s = _property(_itemgetter(
%
d), doc='Alias for field number
%
d')
\n
"
%
(
name
,
i
,
i
)
if
verbose
:
print
(
template
)
...
...
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