Note that the use of the implementation's tracing or debugging
facilities may keep objects alive that would normally be collectable.
Also note that catching an exception with a
-`\code{try}...\code{except}' statement may keep objects alive.
+`\keyword{try}...\keyword{except}' statement may keep objects alive.
Some objects contain references to ``external'' resources such as open
files or windows. It is understood that these resources are freed
not guaranteed to happen, such objects also provide an explicit way to
release the external resource, usually a \method{close()} method.
Programs are strongly recommended to explicitly close such
-objects.
-The `\code{try}...\code{finally}' statement provides a convenient way
-to do this.
+objects. The `\keyword{try}...\keyword{finally}' statement provides
+a convenient way to do this.
Some objects contain references to other objects; these are called
\emph{containers}. Examples of containers are tuples, lists and
\index{attribute}
\indexii{special}{attribute}
\indexiii{generic}{special}{attribute}
-\withsubitem{(built-in object attribute)}{%
+\withsubitem{(built-in object attribute)}{
\ttindex{__methods__}
\ttindex{__members__}}
Sequences are distinguished according to their mutability:
\begin{description}
-%
+
\item[Immutable sequences]
An object of an immutable sequence type cannot change once it is
created. (If the object contains references to other objects,
defined. Additional information about a function's definition can be
retrieved from its code object; see the description of internal types
below.
-\withsubitem{(function attribute)}{%
- \ttindex{func_doc}%
- \ttindex{__doc__}%
- \ttindex{__name__}%
- \ttindex{func_defaults}%
- \ttindex{func_code}%
+\withsubitem{(function attribute)}{
+ \ttindex{func_doc}
+ \ttindex{__doc__}
+ \ttindex{__name__}
+ \ttindex{func_defaults}
+ \ttindex{func_code}
\ttindex{func_globals}}
\indexii{global}{namespace}
\member{__doc__} is the method's documentation (same as
\code{im_func.__doc__}); \member{__name__} is the method name (same as
\code{im_func.__name__}).
-\withsubitem{(method attribute)}{%
- \ttindex{im_func}%
+\withsubitem{(method attribute)}{
+ \ttindex{im_func}
\ttindex{im_self}}
User-defined method objects are created in two ways: when getting an
instance, \code{x.f} yields a bound method object \code{m} where
\code{m.im_class} is \code{C}, \code{m.im_func} is \method{f()}, and
\code{m.im_self} is \code{x}.
-\withsubitem{(method attribute)}{%
- \ttindex{im_class}%
- \ttindex{im_func}%
+\withsubitem{(method attribute)}{
+ \ttindex{im_class}
+ \ttindex{im_func}
\ttindex{im_self}}
When an unbound user-defined method object is called, the underlying
statically linked into the interpreter; for extension modules loaded
dynamically from a shared library, it is the pathname of the shared
library file.
-\withsubitem{(module attribute)}{%
- \ttindex{__name__}%
- \ttindex{__doc__}%
+\withsubitem{(module attribute)}{
+ \ttindex{__name__}
+ \ttindex{__doc__}
\ttindex{__file__}}
\indexii{module}{namespace}
containing the base classes, in the order of their occurrence in the
base class list; \member{__doc__} is the class's documentation string,
or None if undefined.
-\withsubitem{(class attribute)}{%
- \ttindex{__name__}%
- \ttindex{__module__}%
- \ttindex{__dict__}%
- \ttindex{__bases__}%
+\withsubitem{(class attribute)}{
+ \ttindex{__name__}
+ \ttindex{__module__}
+ \ttindex{__dict__}
+ \ttindex{__bases__}
\ttindex{__doc__}}
\item[Class instances]
Special attributes: \member{__dict__} is the attribute
dictionary; \member{__class__} is the instance's class.
-\withsubitem{(instance attribute)}{%
- \ttindex{__dict__}%
+\withsubitem{(instance attribute)}{
+ \ttindex{__dict__}
\ttindex{__class__}}
\item[Files]
\bifuncindex{open}
\withsubitem{(in module os)}{\ttindex{popen()}}
\withsubitem{(socket method)}{\ttindex{makefile()}}
-\withsubitem{(in module sys)}{%
- \ttindex{stdin}%
- \ttindex{stdout}%
+\withsubitem{(in module sys)}{
+ \ttindex{stdin}
+ \ttindex{stdout}
\ttindex{stderr}}
\ttindex{sys.stdin}
\ttindex{sys.stdout}
the interpreter); \member{co_stacksize} is the required stack size
(including local variables); \member{co_flags} is an integer encoding
a number of flags for the interpreter.
-\withsubitem{(code object attribute)}{%
- \ttindex{co_argcount}%
- \ttindex{co_code}%
- \ttindex{co_consts}%
- \ttindex{co_filename}%
- \ttindex{co_firstlineno}%
- \ttindex{co_flags}%
- \ttindex{co_lnotab}%
- \ttindex{co_name}%
- \ttindex{co_names}%
- \ttindex{co_nlocals}%
- \ttindex{co_stacksize}%
+\withsubitem{(code object attribute)}{
+ \ttindex{co_argcount}
+ \ttindex{co_code}
+ \ttindex{co_consts}
+ \ttindex{co_filename}
+ \ttindex{co_firstlineno}
+ \ttindex{co_flags}
+ \ttindex{co_lnotab}
+ \ttindex{co_name}
+ \ttindex{co_names}
+ \ttindex{co_nlocals}
+ \ttindex{co_stacksize}
\ttindex{co_varnames}}
The following flag bits are defined for \member{co_flags}: bit 2 is set
\member{f_lineno} gives the line number and \member{f_lasti} gives the
precise instruction (this is an index into the bytecode string of
the code object).
-\withsubitem{(frame attribute)}{%
- \ttindex{f_back}%
- \ttindex{f_code}%
- \ttindex{f_globals}%
- \ttindex{f_locals}%
- \ttindex{f_lineno}%
- \ttindex{f_lasti}%
- \ttindex{f_builtins}%
+\withsubitem{(frame attribute)}{
+ \ttindex{f_back}
+ \ttindex{f_code}
+ \ttindex{f_globals}
+ \ttindex{f_locals}
+ \ttindex{f_lineno}
+ \ttindex{f_lasti}
+ \ttindex{f_builtins}
\ttindex{f_restricted}}
Special writable attributes: \member{f_trace}, if not \code{None}, is a
the debugger); \member{f_exc_type}, \member{f_exc_value},
\member{f_exc_traceback} represent the most recent exception caught in
this frame.
-\withsubitem{(frame attribute)}{%
- \ttindex{f_trace}%
- \ttindex{f_exc_type}%
- \ttindex{f_exc_value}%
+\withsubitem{(frame attribute)}{
+ \ttindex{f_trace}
+ \ttindex{f_exc_type}
+ \ttindex{f_exc_value}
\ttindex{f_exc_traceback}}
\item[Traceback objects] \label{traceback}
\indexii{stack}{trace}
\indexii{exception}{handler}
\indexii{execution}{stack}
-\withsubitem{(in module sys)}{%
- \ttindex{exc_info}%
- \ttindex{exc_traceback}%
+\withsubitem{(in module sys)}{
+ \ttindex{exc_info}
+ \ttindex{exc_traceback}
\ttindex{last_traceback}}
\ttindex{sys.exc_info}
\ttindex{sys.exc_traceback}
traceback may differ from the line number of its frame object if the
exception occurred in a \keyword{try} statement with no matching
except clause or with a finally clause.
-\withsubitem{(traceback attribute)}{%
- \ttindex{tb_next}%
- \ttindex{tb_frame}%
- \ttindex{tb_lineno}%
+\withsubitem{(traceback attribute)}{
+ \ttindex{tb_next}
+ \ttindex{tb_frame}
+ \ttindex{tb_lineno}
\ttindex{tb_lasti}}
\stindex{try}
Special read-only attributes: \member{start} is the lowerbound;
\member{stop} is the upperbound; \member{step} is the step value; each is
\code{None} if omitted. These attributes can have any type.
-\withsubitem{(slice object attribute)}{%
- \ttindex{start}%
- \ttindex{stop}%
+\withsubitem{(slice object attribute)}{
+ \ttindex{start}
+ \ttindex{stop}
\ttindex{step}}
\end{description} % Internal types
\method{__add__()}, \method{__radd__()}, \method{__mul__()} and
\method{__rmul__()} described below; they should not define
\method{__coerce__()} or other numerical operators.
-\withsubitem{(mapping object method)}{%
- \ttindex{keys()}%
- \ttindex{values()}%
- \ttindex{items()}%
- \ttindex{has_key()}%
- \ttindex{get()}%
- \ttindex{clear()}%
- \ttindex{copy()}%
+\withsubitem{(mapping object method)}{
+ \ttindex{keys()}
+ \ttindex{values()}
+ \ttindex{items()}
+ \ttindex{has_key()}
+ \ttindex{get()}
+ \ttindex{clear()}
+ \ttindex{copy()}
\ttindex{update()}}
-\withsubitem{(sequence object method)}{%
- \ttindex{append()}%
- \ttindex{count()}%
- \ttindex{index()}%
- \ttindex{insert()}%
- \ttindex{pop()}%
- \ttindex{remove()}%
- \ttindex{reverse()}%
- \ttindex{sort()}%
- \ttindex{__add__()}%
- \ttindex{__radd__()}%
- \ttindex{__mul__()}%
+\withsubitem{(sequence object method)}{
+ \ttindex{append()}
+ \ttindex{count()}
+ \ttindex{index()}
+ \ttindex{insert()}
+ \ttindex{pop()}
+ \ttindex{remove()}
+ \ttindex{reverse()}
+ \ttindex{sort()}
+ \ttindex{__add__()}
+ \ttindex{__radd__()}
+ \ttindex{__mul__()}
\ttindex{__rmul__()}}
\withsubitem{(numberic object method)}{\ttindex{__coerce__()}}