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
aaec403a
Kaydet (Commit)
aaec403a
authored
Mar 21, 1995
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
added index entries for __*__ identifiers
üst
3aca2a1f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
130 additions
and
0 deletions
+130
-0
ref3.tex
Doc/ref/ref3.tex
+58
-0
ref4.tex
Doc/ref/ref4.tex
+6
-0
ref8.tex
Doc/ref/ref8.tex
+1
-0
ref3.tex
Doc/ref3.tex
+58
-0
ref4.tex
Doc/ref4.tex
+6
-0
ref8.tex
Doc/ref8.tex
+1
-0
No files found.
Doc/ref/ref3.tex
Dosyayı görüntüle @
aaec403a
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
(The reverse is not true --- if
\verb
@
x
@
is a list object,
(The reverse is not true --- if
\verb
@
x
@
is a list object,
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\ttindex
{__
getitem
__}
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
attempts to execute an
attempts to execute an
...
@@ -594,6 +595,9 @@ object's class and address.
...
@@ -594,6 +595,9 @@ object's class and address.
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
address.
address.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
\ttindex
{__
repr
__}
\ttindex
{__
str
__}
\ttindex
{__
cmp
__}
\subsection
{
Special methods for any type
}
\subsection
{
Special methods for any type
}
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
explicitly call it to ensure proper initialization of the base class
explicitly call it to ensure proper initialization of the base class
part of the instance.
part of the instance.
\ttindex
{__
init
__}
\indexii
{
class
}{
constructor
}
\item
[{\tt __del__(self)}]
\item
[{\tt __del__(self)}]
Called when the instance is about to be destroyed. If a base class
Called when the instance is about to be destroyed. If a base class
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
reference is deleted. It is not guaranteed that
reference is deleted. It is not guaranteed that
\code
{__
del
__}
methods are called for objects that still exist when
\code
{__
del
__}
methods are called for objects that still exist when
the interpreter exits.
the interpreter exits.
\ttindex
{__
del
__}
\stindex
{
del
}
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
former decrements the reference count for
\code
{
x
}
by one, but
former decrements the reference count for
\code
{
x
}
by one, but
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
\item
[{\tt __repr__(self)}]
\item
[{\tt __repr__(self)}]
Called by the
\verb
@
repr()
@
built-in function and by string conversions
Called by the
\verb
@
repr()
@
built-in function and by string conversions
(reverse or backward quotes) to compute the string representation of an object.
(reverse or backward quotes) to compute the string representation of an object.
\ttindex
{__
repr
__}
\bifuncindex
{
repr
}
\indexii
{
string
}{
conversion
}
\indexii
{
string
}{
conversion
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
backward
}{
quotes
}
\indexii
{
backward
}{
quotes
}
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
\item
[{\tt __str__(self)}]
\item
[{\tt __str__(self)}]
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
statement compute the string representation of an object.
statement compute the string representation of an object.
\ttindex
{__
str
__}
\bifuncindex
{
str
}
\stindex
{
print
}
\item
[{\tt __cmp__(self, other)}]
\item
[{\tt __cmp__(self, other)}]
Called by all comparison operations. Should return -1 if
Called by all comparison operations. Should return -1 if
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
(Implementation note: due to limitations in the interpreter,
(Implementation note: due to limitations in the interpreter,
exceptions raised by comparisons are ignored, and the objects will be
exceptions raised by comparisons are ignored, and the objects will be
considered equal in this case.)
considered equal in this case.)
\ttindex
{__
cmp
__}
\bifuncindex
{
cmp
}
\index
{
comparisons
}
\item
[{\tt __hash__(self)}]
\item
[{\tt __hash__(self)}]
Called for the key object for dictionary operations,
Called for the key object for dictionary operations,
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
\code
{__
hash
__}
, since the dictionary implementation assumes that a
\code
{__
hash
__}
, since the dictionary implementation assumes that a
key's hash value is a constant.
key's hash value is a constant.
\obindex
{
dictionary
}
\obindex
{
dictionary
}
\ttindex
{__
cmp
__}
\ttindex
{__
hash
__}
\bifuncindex
{
hash
}
\item
[{\tt __call__(self, *args)}]
\item
[{\tt __call__(self, *args)}]
Called when the instance is ``called'' as a function.
Called when the instance is ``called'' as a function.
\ttindex
{__
call
__}
\indexii
{
call
}{
instance
}
\end{description}
\end{description}
...
@@ -677,6 +699,7 @@ access for class instances.
...
@@ -677,6 +699,7 @@ access for class instances.
Called when an attribute lookup has not found the attribute in the
Called when an attribute lookup has not found the attribute in the
usual places (i.e. it is not an instance attribute nor is it found in
usual places (i.e. it is not an instance attribute nor is it found in
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
\ttindex
{__
getattr
__}
Note that if the attribute is found through the normal mechanism,
Note that if the attribute is found through the normal mechanism,
\code
{__
getattr
__}
is not called. (This is an asymmetry between
\code
{__
getattr
__}
is not called. (This is an asymmetry between
...
@@ -687,22 +710,26 @@ instance.
...
@@ -687,22 +710,26 @@ instance.
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
total control by simply not inserting any values in the instance
total control by simply not inserting any values in the instance
attribute dictionary.
attribute dictionary.
\ttindex
{__
setattr
__}
\item
[{\tt __setattr__(self, name, value)}]
\item
[{\tt __setattr__(self, name, value)}]
Called when an attribute assignment is attempted. This is called
Called when an attribute assignment is attempted. This is called
instead of the normal mechanism (i.e. store the value as an instance
instead of the normal mechanism (i.e. store the value as an instance
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
value to be assigned to it.
value to be assigned to it.
\ttindex
{__
setattr
__}
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
cause a recursive call. Instead, it should insert the value in the
cause a recursive call. Instead, it should insert the value in the
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
value
}
.
value
}
.
\ttindex
{__
dict
__}
\item
[{\tt __delattr__(self, name)}]
\item
[{\tt __delattr__(self, name)}]
Like
\code
{__
setattr
__}
but for attribute deletion instead of
Like
\code
{__
setattr
__}
but for attribute deletion instead of
assignment.
assignment.
\ttindex
{__
delattr
__}
\end{description}
\end{description}
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
Boolean context.
Boolean context.
\ttindex
{__
len
__}
\item
[{\tt __getitem__(self, key)}]
\item
[{\tt __getitem__(self, key)}]
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
special interpretation of negative keys (if the class wishes to
special interpretation of negative keys (if the class wishes to
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
\ttindex
{__
getitem
__}
\item
[{\tt __setitem__(self, key, value)}]
\item
[{\tt __setitem__(self, key, value)}]
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\verb
@
__getitem__
@
.
\ttindex
{__
setitem
__}
\item
[{\tt __delitem__(self, key)}]
\item
[{\tt __delitem__(self, key)}]
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\verb
@
__getitem__
@
.
\ttindex
{__
delitem
__}
\end{description}
\end{description}
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
(unlike for
\verb
@
__getitem__
@
).
(unlike for
\verb
@
__getitem__
@
).
\ttindex
{__
getslice
__}
\item
[{\tt __setslice__(self, i, j, sequence)}]
\item
[{\tt __setslice__(self, i, j, sequence)}]
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\verb
@
__getslice__
@
.
\ttindex
{__
setslice
__}
\item
[{\tt __delslice__(self, i, j)}]
\item
[{\tt __delslice__(self, i, j)}]
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\verb
@
__getslice__
@
.
\ttindex
{__
delslice
__}
\end{description}
\end{description}
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\ttindex
{__
or
__}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\ttindex
{__
rshift
__}
\ttindex
{__
lshift
__}
\ttindex
{__
pow
__}
\ttindex
{__
divmod
__}
\ttindex
{__
mod
__}
\ttindex
{__
div
__}
\ttindex
{__
mul
__}
\ttindex
{__
sub
__}
\ttindex
{__
add
__}
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
\item
[{\tt __invert__(self)}]
\itembreak
\item
[{\tt __invert__(self)}]
\itembreak
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
\verb
@
abs()
@
and
\verb
@
~
@
).
\verb
@
abs()
@
and
\verb
@
~
@
).
\ttindex
{__
invert
__}
\ttindex
{__
abs
__}
\ttindex
{__
pos
__}
\ttindex
{__
neg
__}
\item
[{\tt __nonzero__(self)}]
\item
[{\tt __nonzero__(self)}]
Called to implement boolean testing; should return 0 or 1. An
Called to implement boolean testing; should return 0 or 1. An
alternative name for this method is
\verb
@
__len__
@
.
alternative name for this method is
\verb
@
__len__
@
.
\ttindex
{__
nonzero
__}
\item
[{\tt __coerce__(self, other)}]
\item
[{\tt __coerce__(self, other)}]
Called to implement ``mixed-mode'' numeric arithmetic. Should either
Called to implement ``mixed-mode'' numeric arithmetic. Should either
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
interpreter will also ask the other object to attempt a coercion (but
interpreter will also ask the other object to attempt a coercion (but
sometimes, if the implementation of the other type cannot be changed,
sometimes, if the implementation of the other type cannot be changed,
it is useful to do the conversion to the other type here).
it is useful to do the conversion to the other type here).
\ttindex
{__
coerce
__}
Note that this method is not called to coerce the arguments to
\verb
@
+
@
Note that this method is not called to coerce the arguments to
\verb
@
+
@
and
\verb
@
*
@
, because these are also used to implement sequence
and
\verb
@
*
@
, because these are also used to implement sequence
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
\footnote
{
The interpreter should really distinguish between
\footnote
{
The interpreter should really distinguish between
user-defined classes implementing sequences, mappings or numbers, but
user-defined classes implementing sequences, mappings or numbers, but
currently it doesn't --- hence this strange exception.
}
currently it doesn't --- hence this strange exception.
}
\ttindex
{__
mul
__}
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __float__(self)}]
\itembreak
\item
[{\tt __float__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
and
\verb
@
float()
@
. Should return a value of the appropriate type.
and
\verb
@
float()
@
. Should return a value of the appropriate type.
\ttindex
{__
float
__}
\ttindex
{__
long
__}
\ttindex
{__
int
__}
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __hex__(self)}]
\itembreak
\item
[{\tt __hex__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
oct()
@
and
Called to implement the built-in functions
\verb
@
oct()
@
and
\verb
@
hex()
@
. Should return a string value.
\verb
@
hex()
@
. Should return a string value.
\ttindex
{__
hex
__}
\ttindex
{__
oct
__}
\end{description}
\end{description}
Doc/ref/ref4.tex
Dosyayı görüntüle @
aaec403a
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
lookup first searches the local name space, then the global one, then
lookup first searches the local name space, then the global one, then
the built-in one.
}
the built-in one.
}
\bimodindex
{__
builtin
__}
\stindex
{
from
}
\stindex
{
exec
}
\stindex
{
global
}
\ttindex
{
NameError
}
The following table lists the meaning of the local and global name
The following table lists the meaning of the local and global name
space for various types of code blocks. The name space for a
space for various types of code blocks. The name space for a
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
\hline
\hline
\end{tabular}
\end{tabular}
\end{center}
\end{center}
\bimodindex
{__
main
__}
Notes:
Notes:
...
...
Doc/ref/ref8.tex
Dosyayı görüntüle @
aaec403a
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
is identical to that of a complete program; each statement is executed
is identical to that of a complete program; each statement is executed
in the name space of
\verb
@
__main__
@
.
in the name space of
\verb
@
__main__
@
.
\index
{
interactive mode
}
\index
{
interactive mode
}
\bimodindex
{__
main
__}
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
...
...
Doc/ref3.tex
Dosyayı görüntüle @
aaec403a
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
...
@@ -585,6 +585,7 @@ method named \verb@__getitem__@, and \verb@x@ is an instance of this
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
class, then
\verb
@
x[i]
@
is equivalent to
\verb
@
x.__getitem__(i)
@
.
(The reverse is not true --- if
\verb
@
x
@
is a list object,
(The reverse is not true --- if
\verb
@
x
@
is a list object,
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\verb
@
x.__getitem__(i)
@
is not equivalent to
\verb
@
x[i]
@
.)
\ttindex
{__
getitem
__}
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
Except for
\verb
@
__repr__
@
,
\verb
@
__str__
@
and
\verb
@
__cmp__
@
,
attempts to execute an
attempts to execute an
...
@@ -594,6 +595,9 @@ object's class and address.
...
@@ -594,6 +595,9 @@ object's class and address.
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
For
\verb
@
__cmp__
@
, the default is to compare instances based on their
address.
address.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
For
\verb
@
__str__
@
, the default is to use
\verb
@
__repr__
@
.
\ttindex
{__
repr
__}
\ttindex
{__
str
__}
\ttindex
{__
cmp
__}
\subsection
{
Special methods for any type
}
\subsection
{
Special methods for any type
}
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
...
@@ -606,6 +610,9 @@ to the class constructor expression. If a base class has an
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
\code
{__
init
__}
method the derived class's
\code
{__
init
__}
method must
explicitly call it to ensure proper initialization of the base class
explicitly call it to ensure proper initialization of the base class
part of the instance.
part of the instance.
\ttindex
{__
init
__}
\indexii
{
class
}{
constructor
}
\item
[{\tt __del__(self)}]
\item
[{\tt __del__(self)}]
Called when the instance is about to be destroyed. If a base class
Called when the instance is about to be destroyed. If a base class
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
...
@@ -617,6 +624,8 @@ reference to it. It may then be called at a later time when this new
reference is deleted. It is not guaranteed that
reference is deleted. It is not guaranteed that
\code
{__
del
__}
methods are called for objects that still exist when
\code
{__
del
__}
methods are called for objects that still exist when
the interpreter exits.
the interpreter exits.
\ttindex
{__
del
__}
\stindex
{
del
}
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
Note that
\code
{
del x
}
doesn't directly call
\code
{
x.
__
del
__}
--- the
former decrements the reference count for
\code
{
x
}
by one, but
former decrements the reference count for
\code
{
x
}
by one, but
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
...
@@ -625,6 +634,8 @@ former decrements the reference count for \code{x} by one, but
\item
[{\tt __repr__(self)}]
\item
[{\tt __repr__(self)}]
Called by the
\verb
@
repr()
@
built-in function and by string conversions
Called by the
\verb
@
repr()
@
built-in function and by string conversions
(reverse or backward quotes) to compute the string representation of an object.
(reverse or backward quotes) to compute the string representation of an object.
\ttindex
{__
repr
__}
\bifuncindex
{
repr
}
\indexii
{
string
}{
conversion
}
\indexii
{
string
}{
conversion
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
reverse
}{
quotes
}
\indexii
{
backward
}{
quotes
}
\indexii
{
backward
}{
quotes
}
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
...
@@ -633,6 +644,9 @@ Called by the \verb@repr()@ built-in function and by string conversions
\item
[{\tt __str__(self)}]
\item
[{\tt __str__(self)}]
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
Called by the
\verb
@
str()
@
built-in function and by the
\verb
@
print
@
statement compute the string representation of an object.
statement compute the string representation of an object.
\ttindex
{__
str
__}
\bifuncindex
{
str
}
\stindex
{
print
}
\item
[{\tt __cmp__(self, other)}]
\item
[{\tt __cmp__(self, other)}]
Called by all comparison operations. Should return -1 if
Called by all comparison operations. Should return -1 if
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
...
@@ -642,6 +656,9 @@ instances are compared by object identity (``address'').
(Implementation note: due to limitations in the interpreter,
(Implementation note: due to limitations in the interpreter,
exceptions raised by comparisons are ignored, and the objects will be
exceptions raised by comparisons are ignored, and the objects will be
considered equal in this case.)
considered equal in this case.)
\ttindex
{__
cmp
__}
\bifuncindex
{
cmp
}
\index
{
comparisons
}
\item
[{\tt __hash__(self)}]
\item
[{\tt __hash__(self)}]
Called for the key object for dictionary operations,
Called for the key object for dictionary operations,
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
...
@@ -659,9 +676,14 @@ implements a \code{__cmp__} method it should not implement
\code
{__
hash
__}
, since the dictionary implementation assumes that a
\code
{__
hash
__}
, since the dictionary implementation assumes that a
key's hash value is a constant.
key's hash value is a constant.
\obindex
{
dictionary
}
\obindex
{
dictionary
}
\ttindex
{__
cmp
__}
\ttindex
{__
hash
__}
\bifuncindex
{
hash
}
\item
[{\tt __call__(self, *args)}]
\item
[{\tt __call__(self, *args)}]
Called when the instance is ``called'' as a function.
Called when the instance is ``called'' as a function.
\ttindex
{__
call
__}
\indexii
{
call
}{
instance
}
\end{description}
\end{description}
...
@@ -677,6 +699,7 @@ access for class instances.
...
@@ -677,6 +699,7 @@ access for class instances.
Called when an attribute lookup has not found the attribute in the
Called when an attribute lookup has not found the attribute in the
usual places (i.e. it is not an instance attribute nor is it found in
usual places (i.e. it is not an instance attribute nor is it found in
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
the class tree for
\code
{
self
}
).
\code
{
name
}
is the attribute name.
\ttindex
{__
getattr
__}
Note that if the attribute is found through the normal mechanism,
Note that if the attribute is found through the normal mechanism,
\code
{__
getattr
__}
is not called. (This is an asymmetry between
\code
{__
getattr
__}
is not called. (This is an asymmetry between
...
@@ -687,22 +710,26 @@ instance.
...
@@ -687,22 +710,26 @@ instance.
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
Note that at least for instance variables,
\code
{__
getattr
__}
can fake
total control by simply not inserting any values in the instance
total control by simply not inserting any values in the instance
attribute dictionary.
attribute dictionary.
\ttindex
{__
setattr
__}
\item
[{\tt __setattr__(self, name, value)}]
\item
[{\tt __setattr__(self, name, value)}]
Called when an attribute assignment is attempted. This is called
Called when an attribute assignment is attempted. This is called
instead of the normal mechanism (i.e. store the value as an instance
instead of the normal mechanism (i.e. store the value as an instance
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
attribute).
\code
{
name
}
is the attribute name,
\code
{
value
}
is the
value to be assigned to it.
value to be assigned to it.
\ttindex
{__
setattr
__}
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
If
\code
{__
setattr
__}
wants to assign to an instance attribute, it
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
should not simply execute
\code
{
self.
\var
{
name
}
= value
}
--- this would
cause a recursive call. Instead, it should insert the value in the
cause a recursive call. Instead, it should insert the value in the
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
dictionary of instance attributes, e.g.
\code
{
self.
__
dict
__
[name] =
value
}
.
value
}
.
\ttindex
{__
dict
__}
\item
[{\tt __delattr__(self, name)}]
\item
[{\tt __delattr__(self, name)}]
Like
\code
{__
setattr
__}
but for attribute deletion instead of
Like
\code
{__
setattr
__}
but for attribute deletion instead of
assignment.
assignment.
\ttindex
{__
delattr
__}
\end{description}
\end{description}
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
...
@@ -716,19 +743,23 @@ Called to implement the built-in function \verb@len()@. Should return
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
the length of the object, an integer
\verb
@
>=
@
0. Also, an object
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
whose
\verb
@
__len__()
@
method returns 0 is considered to be false in a
Boolean context.
Boolean context.
\ttindex
{__
len
__}
\item
[{\tt __getitem__(self, key)}]
\item
[{\tt __getitem__(self, key)}]
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
Called to implement evaluation of
\verb
@
self[key]
@
. Note that the
special interpretation of negative keys (if the class wishes to
special interpretation of negative keys (if the class wishes to
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
emulate a sequence type) is up to the
\verb
@
__getitem__
@
method.
\ttindex
{__
getitem
__}
\item
[{\tt __setitem__(self, key, value)}]
\item
[{\tt __setitem__(self, key, value)}]
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
Called to implement assignment to
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\verb
@
__getitem__
@
.
\ttindex
{__
setitem
__}
\item
[{\tt __delitem__(self, key)}]
\item
[{\tt __delitem__(self, key)}]
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
Called to implement deletion of
\verb
@
self[key]
@
. Same note as for
\verb
@
__getitem__
@
.
\verb
@
__getitem__
@
.
\ttindex
{__
delitem
__}
\end{description}
\end{description}
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
...
@@ -743,14 +774,17 @@ Called to implement evaluation of \verb@self[i:j]@. Note that missing
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
respectively, and
\verb
@
len(self)
@
has been added (once) to originally
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
negative
\verb
@
i
@
or
\verb
@
j
@
by the time this function is called
(unlike for
\verb
@
__getitem__
@
).
(unlike for
\verb
@
__getitem__
@
).
\ttindex
{__
getslice
__}
\item
[{\tt __setslice__(self, i, j, sequence)}]
\item
[{\tt __setslice__(self, i, j, sequence)}]
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
Called to implement assignment to
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\verb
@
__getslice__
@
.
\ttindex
{__
setslice
__}
\item
[{\tt __delslice__(self, i, j)}]
\item
[{\tt __delslice__(self, i, j)}]
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
Called to implement deletion of
\verb
@
self[i:j]
@
. Same notes as for
\verb
@
__getslice__
@
.
\verb
@
__getslice__
@
.
\ttindex
{__
delslice
__}
\end{description}
\end{description}
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
...
@@ -774,6 +808,18 @@ Called to implement deletion of \verb@self[i:j]@. Same notes as for
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
Called to implement the binary arithmetic operations (
\verb
@
+
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
-
@
,
\verb
@
*
@
,
\verb
@
/
@
,
\verb
@
%
@
,
\verb
@
divmod()
@
,
\verb
@
pow()
@
,
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\verb
@
<<
@
,
\verb
@
>>
@
,
\verb
@
&
@
,
\verb
@
^
@
,
\verb
@
|
@
).
\ttindex
{__
or
__}
\ttindex
{__
xor
__}
\ttindex
{__
and
__}
\ttindex
{__
rshift
__}
\ttindex
{__
lshift
__}
\ttindex
{__
pow
__}
\ttindex
{__
divmod
__}
\ttindex
{__
mod
__}
\ttindex
{__
div
__}
\ttindex
{__
mul
__}
\ttindex
{__
sub
__}
\ttindex
{__
add
__}
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __neg__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
\item
[{\tt __pos__(self)}]
\itemjoin
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
...
@@ -781,10 +827,15 @@ Called to implement the binary arithmetic operations (\verb@+@,
\item
[{\tt __invert__(self)}]
\itembreak
\item
[{\tt __invert__(self)}]
\itembreak
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
Called to implement the unary arithmetic operations (
\verb
@
-
@
,
\verb
@
+
@
,
\verb
@
abs()
@
and
\verb
@
~
@
).
\verb
@
abs()
@
and
\verb
@
~
@
).
\ttindex
{__
invert
__}
\ttindex
{__
abs
__}
\ttindex
{__
pos
__}
\ttindex
{__
neg
__}
\item
[{\tt __nonzero__(self)}]
\item
[{\tt __nonzero__(self)}]
Called to implement boolean testing; should return 0 or 1. An
Called to implement boolean testing; should return 0 or 1. An
alternative name for this method is
\verb
@
__len__
@
.
alternative name for this method is
\verb
@
__len__
@
.
\ttindex
{__
nonzero
__}
\item
[{\tt __coerce__(self, other)}]
\item
[{\tt __coerce__(self, other)}]
Called to implement ``mixed-mode'' numeric arithmetic. Should either
Called to implement ``mixed-mode'' numeric arithmetic. Should either
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
...
@@ -794,6 +845,7 @@ would be the type of other, it is sufficient to return None, since the
interpreter will also ask the other object to attempt a coercion (but
interpreter will also ask the other object to attempt a coercion (but
sometimes, if the implementation of the other type cannot be changed,
sometimes, if the implementation of the other type cannot be changed,
it is useful to do the conversion to the other type here).
it is useful to do the conversion to the other type here).
\ttindex
{__
coerce
__}
Note that this method is not called to coerce the arguments to
\verb
@
+
@
Note that this method is not called to coerce the arguments to
\verb
@
+
@
and
\verb
@
*
@
, because these are also used to implement sequence
and
\verb
@
*
@
, because these are also used to implement sequence
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
...
@@ -803,16 +855,22 @@ same reason, in \verb@n*x@, where \verb@n@ is a built-in number and
\footnote
{
The interpreter should really distinguish between
\footnote
{
The interpreter should really distinguish between
user-defined classes implementing sequences, mappings or numbers, but
user-defined classes implementing sequences, mappings or numbers, but
currently it doesn't --- hence this strange exception.
}
currently it doesn't --- hence this strange exception.
}
\ttindex
{__
mul
__}
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __int__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __long__(self)}]
\itemjoin
\item
[{\tt __float__(self)}]
\itembreak
\item
[{\tt __float__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
Called to implement the built-in functions
\verb
@
int()
@
,
\verb
@
long()
@
and
\verb
@
float()
@
. Should return a value of the appropriate type.
and
\verb
@
float()
@
. Should return a value of the appropriate type.
\ttindex
{__
float
__}
\ttindex
{__
long
__}
\ttindex
{__
int
__}
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __oct__(self)}]
\itemjoin
\item
[{\tt __hex__(self)}]
\itembreak
\item
[{\tt __hex__(self)}]
\itembreak
Called to implement the built-in functions
\verb
@
oct()
@
and
Called to implement the built-in functions
\verb
@
oct()
@
and
\verb
@
hex()
@
. Should return a string value.
\verb
@
hex()
@
. Should return a string value.
\ttindex
{__
hex
__}
\ttindex
{__
oct
__}
\end{description}
\end{description}
Doc/ref4.tex
Dosyayı görüntüle @
aaec403a
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
...
@@ -77,6 +77,11 @@ construct {\tt from \ldots import *}, the semantics of names not
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
explicitly mentioned in a
{
\tt
global
}
statement change subtly: name
lookup first searches the local name space, then the global one, then
lookup first searches the local name space, then the global one, then
the built-in one.
}
the built-in one.
}
\bimodindex
{__
builtin
__}
\stindex
{
from
}
\stindex
{
exec
}
\stindex
{
global
}
\ttindex
{
NameError
}
The following table lists the meaning of the local and global name
The following table lists the meaning of the local and global name
space for various types of code blocks. The name space for a
space for various types of code blocks. The name space for a
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
...
@@ -107,6 +112,7 @@ Expression read by \verb@input@
\hline
\hline
\end{tabular}
\end{tabular}
\end{center}
\end{center}
\bimodindex
{__
main
__}
Notes:
Notes:
...
...
Doc/ref8.tex
Dosyayı görüntüle @
aaec403a
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
...
@@ -31,6 +31,7 @@ one statement (possibly compound) at a time. The initial environment
is identical to that of a complete program; each statement is executed
is identical to that of a complete program; each statement is executed
in the name space of
\verb
@
__main__
@
.
in the name space of
\verb
@
__main__
@
.
\index
{
interactive mode
}
\index
{
interactive mode
}
\bimodindex
{__
main
__}
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
Under
{
\UNIX
}
, a complete program can be passed to the interpreter in
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
three forms: with the
{
\bf
-c
}
{
\it
string
}
command line option, as a
...
...
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