| 
									
										
										
										
											1998-08-10 19:42:37 +00:00
										 |  |  | \section{\module{types} --- | 
					
						
							| 
									
										
										
										
											2003-01-10 09:33:08 +00:00
										 |  |  |          Names for built-in types} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | \declaremodule{standard}{types} | 
					
						
							| 
									
										
										
										
											2003-01-10 09:33:08 +00:00
										 |  |  | \modulesynopsis{Names for built-in types.} | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-01-10 09:33:08 +00:00
										 |  |  | This module defines names for types some object types that are used by | 
					
						
							|  |  |  | the standard Python interpreter, but not for the types defined by various | 
					
						
							|  |  |  | extension modules.  Also, it does not include some of the types that | 
					
						
							|  |  |  | arise during processing such the \code{listiterator} type. | 
					
						
							|  |  |  | It is safe to use \samp{from types import *} --- | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | 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}. | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | Typical use is for functions that do different things depending on | 
					
						
							|  |  |  | their argument types, like the following: | 
					
						
							| 
									
										
										
										
											1998-03-16 05:23:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \begin{verbatim} | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | from types import * | 
					
						
							| 
									
										
										
										
											2003-01-10 09:33:08 +00:00
										 |  |  | def delete(mylist, item): | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  |     if type(item) is IntType: | 
					
						
							| 
									
										
										
										
											2003-01-10 09:33:08 +00:00
										 |  |  |        del mylist[item] | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |        mylist.remove(item) | 
					
						
							|  |  |  | \end{verbatim} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Starting in Python 2.2, built-in factory functions such as | 
					
						
							|  |  |  | \function{int()} and \function{str()} are also names for the | 
					
						
							|  |  |  | corresponding types.  This is now the preferred way to access | 
					
						
							|  |  |  | the type instead of using the \module{types} module.  Accordingly, | 
					
						
							|  |  |  | the example above should be written as follows: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{verbatim} | 
					
						
							|  |  |  | def delete(mylist, item): | 
					
						
							|  |  |  |     if isinstance(item, int): | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  |        del list[item] | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |        list.remove(item) | 
					
						
							| 
									
										
										
										
											1998-02-13 06:58:54 +00:00
										 |  |  | \end{verbatim} | 
					
						
							| 
									
										
										
										
											1998-03-16 05:23:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | The module defines the following names: | 
					
						
							| 
									
										
										
										
											1994-01-02 01:22:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \begin{datadesc}{NoneType} | 
					
						
							|  |  |  | The type of \code{None}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{TypeType} | 
					
						
							|  |  |  | The type of type objects (such as returned by | 
					
						
							|  |  |  | \function{type()}\bifuncindex{type}). | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-22 02:44:24 +00:00
										 |  |  | \begin{datadesc}{BooleanType} | 
					
						
							|  |  |  | The type of the \class{bool} values \code{True} and \code{False}; this | 
					
						
							|  |  |  | is an alias of the built-in \function{bool()} function. | 
					
						
							|  |  |  | \versionadded{2.3} | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \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} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 15:01:05 +00:00
										 |  |  | \begin{datadesc}{ComplexType} | 
					
						
							| 
									
										
										
										
											2002-05-21 14:28:22 +00:00
										 |  |  | The type of complex numbers (e.g. \code{1.0j}).  This is not defined | 
					
						
							|  |  |  | if Python was built without complex number support. | 
					
						
							| 
									
										
										
										
											1998-07-24 15:01:05 +00:00
										 |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \begin{datadesc}{StringType} | 
					
						
							|  |  |  | The type of character strings (e.g. \code{'Spam'}). | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-06 15:05:04 +00:00
										 |  |  | \begin{datadesc}{UnicodeType} | 
					
						
							| 
									
										
										
										
											2002-05-21 14:28:22 +00:00
										 |  |  | The type of Unicode character strings (e.g. \code{u'Spam'}).  This is | 
					
						
							|  |  |  | not defined if Python was built without Unicode support. | 
					
						
							| 
									
										
										
										
											2000-04-06 15:05:04 +00:00
										 |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \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} | 
					
						
							|  |  |  | An alternate name for \code{DictType}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{FunctionType} | 
					
						
							|  |  |  | The type of user-defined functions and lambdas. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{LambdaType} | 
					
						
							|  |  |  | An alternate name for \code{FunctionType}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-25 19:46:25 +00:00
										 |  |  | \begin{datadesc}{GeneratorType} | 
					
						
							|  |  |  | The type of generator-iterator objects, produced by calling a | 
					
						
							|  |  |  | generator function. | 
					
						
							|  |  |  | \versionadded{2.2} | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \begin{datadesc}{CodeType} | 
					
						
							|  |  |  | The type for code objects such as returned by | 
					
						
							|  |  |  | \function{compile()}\bifuncindex{compile}. | 
					
						
							|  |  |  | \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} | 
					
						
							|  |  |  | An alternate name for \code{MethodType}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{BuiltinFunctionType} | 
					
						
							|  |  |  | The type of built-in functions like \function{len()} or | 
					
						
							|  |  |  | \function{sys.exit()}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{BuiltinMethodType} | 
					
						
							|  |  |  | An alternate name for \code{BuiltinFunction}. | 
					
						
							|  |  |  | \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} | 
					
						
							|  |  |  | The type of range objects returned by | 
					
						
							|  |  |  | \function{xrange()}\bifuncindex{xrange}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 15:01:05 +00:00
										 |  |  | \begin{datadesc}{SliceType} | 
					
						
							|  |  |  | The type of objects returned by | 
					
						
							|  |  |  | \function{slice()}\bifuncindex{slice}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{EllipsisType} | 
					
						
							|  |  |  | The type of \code{Ellipsis}. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-07-24 14:27:22 +00:00
										 |  |  | \begin{datadesc}{TracebackType} | 
					
						
							|  |  |  | The type of traceback objects such as found in | 
					
						
							|  |  |  | \code{sys.exc_traceback}. | 
					
						
							|  |  |  | \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} | 
					
						
							| 
									
										
										
										
											2000-04-03 20:13:55 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{BufferType} | 
					
						
							|  |  |  | The type of buffer objects created by the | 
					
						
							|  |  |  | \function{buffer()}\bifuncindex{buffer} function. | 
					
						
							|  |  |  | \end{datadesc} | 
					
						
							| 
									
										
										
										
											2001-09-29 13:49:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | \begin{datadesc}{StringTypes} | 
					
						
							| 
									
										
										
										
											2002-05-21 14:28:22 +00:00
										 |  |  | A sequence containing \code{StringType} and \code{UnicodeType} used to | 
					
						
							|  |  |  | facilitate easier checking for any string object.  Using this is more | 
					
						
							|  |  |  | portable than using a sequence of the two string types constructed | 
					
						
							|  |  |  | elsewhere since it only contains \code{UnicodeType} if it has been | 
					
						
							|  |  |  | built in the running version of Python.  For example: | 
					
						
							|  |  |  | \code{isinstance(s, types.StringTypes)}. | 
					
						
							| 
									
										
										
										
											2002-05-22 02:44:24 +00:00
										 |  |  | \versionadded{2.2} | 
					
						
							| 
									
										
										
										
											2001-09-29 13:49:41 +00:00
										 |  |  | \end{datadesc} |