types -- Python library reference



Next: traceback Prev: sys Up: Python Services Top: Top

3.2. Standard Module types

This module defines names for all object types that are used by the standard Python interpreter (but not for the types defined by various extension modules). It is safe to use ``from types import *'' --- the module does not export any other names besides the ones listed here. New names exported by future versions of this module will all end in Type.

Typical use is for functions that do different things depending on their argument types, like the following:

from types import *

def delete(list, item):

if type(item) is IntType:

del list[item]

else:

list.remove(item)

The module defines the following names:

NoneType -- data of module types
The type of None.
TypeType -- data of module types
The type of type objects (such as returned by type()).
IntType -- data of module types
The type of integers (e.g. 1).
LongType -- data of module types
The type of long integers (e.g. 1L).
FloatType -- data of module types
The type of floating point numbers (e.g. 1.0).
StringType -- data of module types
The type of character strings (e.g. 'Spam').
TupleType -- data of module types
The type of tuples (e.g. (1, 2, 3, 'Spam')).
ListType -- data of module types
The type of lists (e.g. [0, 1, 2, 3]).
DictType -- data of module types
The type of dictionaries (e.g. {'Bacon': 1, 'Ham': 0}).
DictionaryType -- data of module types
An alternative name for DictType.
FunctionType -- data of module types
The type of user-defined functions and lambdas.
LambdaType -- data of module types
An alternative name for FunctionType.
CodeType -- data of module types
The type for code objects such as returned by compile().
ClassType -- data of module types
The type of user-defined classes.
InstanceType -- data of module types
The type of instances of user-defined classes.
MethodType -- data of module types
The type of methods of user-defined class instances.
UnboundMethodType -- data of module types
An alternative name for MethodType.
BuiltinFunctionType -- data of module types
The type of built-in functions like len or sys.exit.
BuiltinMethodType -- data of module types
An alternative name for BuiltinFunction.
ModuleType -- data of module types
The type of modules.
FileType -- data of module types
The type of open file objects such as sys.stdout.
XRangeType -- data of module types
The type of range objects returned by xrange().
TracebackType -- data of module types
The type of traceback objects such as found in sys.exc_traceback.
FrameType -- data of module types
The type of frame objects such as found in tb.tb_frame if tb is a traceback object.


Next: traceback Prev: sys Up: Python Services Top: Top