1998-04-03 03:12:52 -04:00
|
|
|
\section{Standard Module \module{types}}
|
1997-07-17 13:34:52 -03:00
|
|
|
\label{module-types}
|
1995-02-27 13:53:25 -04:00
|
|
|
\stmodindex{types}
|
|
|
|
|
1995-03-01 11:38:16 -04:00
|
|
|
|
1995-02-27 13:53:25 -04:00
|
|
|
This module defines names for all object types that are used by the
|
1998-03-08 01:41:11 -04:00
|
|
|
standard Python interpreter, but not for the types defined by various
|
|
|
|
extension modules. It is safe to use \samp{from types import *} ---
|
|
|
|
the module does not export any names besides the ones listed here.
|
|
|
|
New names exported by future versions of this module will all end in
|
|
|
|
\samp{Type}.
|
1995-02-27 13:53:25 -04:00
|
|
|
|
|
|
|
Typical use is for functions that do different things depending on
|
|
|
|
their argument types, like the following:
|
|
|
|
|
1998-02-13 02:58:54 -04:00
|
|
|
\begin{verbatim}
|
1995-02-27 13:53:25 -04:00
|
|
|
from types import *
|
|
|
|
def delete(list, item):
|
|
|
|
if type(item) is IntType:
|
|
|
|
del list[item]
|
|
|
|
else:
|
|
|
|
list.remove(item)
|
1998-02-13 02:58:54 -04:00
|
|
|
\end{verbatim}
|
1998-03-08 01:41:11 -04:00
|
|
|
|
1995-02-27 13:53:25 -04:00
|
|
|
The module defines the following names:
|
|
|
|
|
|
|
|
\begin{datadesc}{NoneType}
|
|
|
|
The type of \code{None}.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{TypeType}
|
1998-03-08 01:41:11 -04:00
|
|
|
The type of type objects (such as returned by
|
|
|
|
\function{type()}\bifuncindex{type}).
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{IntType}
|
|
|
|
The type of integers (e.g. \code{1}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{LongType}
|
|
|
|
The type of long integers (e.g. \code{1L}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{FloatType}
|
|
|
|
The type of floating point numbers (e.g. \code{1.0}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{StringType}
|
|
|
|
The type of character strings (e.g. \code{'Spam'}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{TupleType}
|
|
|
|
The type of tuples (e.g. \code{(1, 2, 3, 'Spam')}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{ListType}
|
|
|
|
The type of lists (e.g. \code{[0, 1, 2, 3]}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{DictType}
|
|
|
|
The type of dictionaries (e.g. \code{\{'Bacon': 1, 'Ham': 0\}}).
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{DictionaryType}
|
1998-04-03 03:12:52 -04:00
|
|
|
An alternate name for \code{DictType}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{FunctionType}
|
|
|
|
The type of user-defined functions and lambdas.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{LambdaType}
|
1998-04-03 03:12:52 -04:00
|
|
|
An alternate name for \code{FunctionType}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{CodeType}
|
1998-03-08 01:41:11 -04:00
|
|
|
The type for code objects such as returned by
|
|
|
|
\function{compile()}\bifuncindex{compile}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{ClassType}
|
|
|
|
The type of user-defined classes.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{InstanceType}
|
|
|
|
The type of instances of user-defined classes.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{MethodType}
|
|
|
|
The type of methods of user-defined class instances.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{UnboundMethodType}
|
1998-04-03 03:12:52 -04:00
|
|
|
An alternate name for \code{MethodType}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{BuiltinFunctionType}
|
1998-03-08 01:41:11 -04:00
|
|
|
The type of built-in functions like \function{len()} or
|
|
|
|
\function{sys.exit()}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{BuiltinMethodType}
|
1998-04-03 03:12:52 -04:00
|
|
|
An alternate name for \code{BuiltinFunction}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{ModuleType}
|
|
|
|
The type of modules.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{FileType}
|
|
|
|
The type of open file objects such as \code{sys.stdout}.
|
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{XRangeType}
|
1998-03-08 01:41:11 -04:00
|
|
|
The type of range objects returned by
|
|
|
|
\function{xrange()}\bifuncindex{xrange}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{TracebackType}
|
1998-03-08 01:41:11 -04:00
|
|
|
The type of traceback objects such as found in
|
|
|
|
\code{sys.exc_traceback}.
|
1995-02-27 13:53:25 -04:00
|
|
|
\end{datadesc}
|
|
|
|
|
|
|
|
\begin{datadesc}{FrameType}
|
|
|
|
The type of frame objects such as found in \code{tb.tb_frame} if
|
|
|
|
\code{tb} is a traceback object.
|
|
|
|
\end{datadesc}
|