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
28137a09
Kaydet (Commit)
28137a09
authored
May 20, 2003
tarafından
Andrew M. Kuchling
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Don't mention __slots__ as a technique for error avoidance
üst
e960e225
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
10 deletions
+6
-10
whatsnew22.tex
Doc/whatsnew/whatsnew22.tex
+6
-10
No files found.
Doc/whatsnew/whatsnew22.tex
Dosyayı görüntüle @
28137a09
...
...
@@ -424,14 +424,9 @@ Finally, it's possible to constrain the list of attributes that can be
referenced on an object using the new
\member
{__
slots
__}
class attribute.
Python objects are usually very dynamic; at any time it's possible to
define a new attribute on an instance by just doing
\code
{
obj.new
_
attr=1
}
. This is flexible and convenient, but this
flexibility can also lead to bugs, as when you meant to write
\code
{
obj.template = 'a'
}
but made a typo and wrote
\code
{
obj.templtae
}
by accident.
A new-style class can define a class attribute named
\member
{__
slots
__}
to constrain the list of legal attribute names. An example will make
this clear:
\code
{
obj.new
_
attr=1
}
. A new-style class can define a class attribute named
\member
{__
slots
__}
to limit the legal attributes
to a particular set of names. An example will make this clear:
\begin{verbatim}
>>> class C(object):
...
...
@@ -443,16 +438,17 @@ None
>>> obj.template = 'Test'
>>> print obj.template
Test
>>> obj.
templtae
= None
>>> obj.
newattr
= None
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'C' object has no attribute '
templtae
'
AttributeError: 'C' object has no attribute '
newattr
'
\end{verbatim}
Note how you get an
\exception
{
AttributeError
}
on the attempt to
assign to an attribute not listed in
\member
{__
slots
__}
.
\subsection
{
Related Links
}
\label
{
sect-rellinks
}
...
...
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