home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / p / python / pyhtmldoc / t / types < prev   
Text File  |  1996-11-14  |  4KB  |  99 lines

  1. <TITLE>types -- Python library reference</TITLE>
  2. Next: <A HREF="../t/traceback" TYPE="Next">traceback</A>  
  3. Prev: <A HREF="../s/sys" TYPE="Prev">sys</A>  
  4. Up: <A HREF="../p/python_services" TYPE="Up">Python Services</A>  
  5. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  6. <H1>3.2. Standard Module <CODE>types</CODE></H1>
  7. This module defines names for all object types that are used by the
  8. standard Python interpreter (but not for the types defined by various
  9. extension modules).  It is safe to use ``<CODE>from types import *</CODE>'' ---
  10. the module does not export any other names besides the ones listed
  11. here.  New names exported by future versions of this module will
  12. all end in <CODE>Type</CODE>.
  13. <P>
  14. Typical use is for functions that do different things depending on
  15. their argument types, like the following:
  16. <P>
  17. <UL COMPACT><CODE>from types import *<P>
  18. def delete(list, item):<P>
  19.     if type(item) is IntType:<P>
  20.        del list[item]<P>
  21.     else:<P>
  22.        list.remove(item)<P>
  23. </CODE></UL>
  24. The module defines the following names:
  25. <P>
  26. <DL><DT><B>NoneType</B> -- data of module types<DD>
  27. The type of <CODE>None</CODE>.
  28. </DL>
  29. <DL><DT><B>TypeType</B> -- data of module types<DD>
  30. The type of type objects (such as returned by <CODE>type()</CODE>).
  31. </DL>
  32. <DL><DT><B>IntType</B> -- data of module types<DD>
  33. The type of integers (e.g. <CODE>1</CODE>).
  34. </DL>
  35. <DL><DT><B>LongType</B> -- data of module types<DD>
  36. The type of long integers (e.g. <CODE>1L</CODE>).
  37. </DL>
  38. <DL><DT><B>FloatType</B> -- data of module types<DD>
  39. The type of floating point numbers (e.g. <CODE>1.0</CODE>).
  40. </DL>
  41. <DL><DT><B>StringType</B> -- data of module types<DD>
  42. The type of character strings (e.g. <CODE>'Spam'</CODE>).
  43. </DL>
  44. <DL><DT><B>TupleType</B> -- data of module types<DD>
  45. The type of tuples (e.g. <CODE>(1, 2, 3, 'Spam')</CODE>).
  46. </DL>
  47. <DL><DT><B>ListType</B> -- data of module types<DD>
  48. The type of lists (e.g. <CODE>[0, 1, 2, 3]</CODE>).
  49. </DL>
  50. <DL><DT><B>DictType</B> -- data of module types<DD>
  51. The type of dictionaries (e.g. <CODE>{'Bacon': 1, 'Ham': 0}</CODE>).
  52. </DL>
  53. <DL><DT><B>DictionaryType</B> -- data of module types<DD>
  54. An alternative name for <CODE>DictType</CODE>.
  55. </DL>
  56. <DL><DT><B>FunctionType</B> -- data of module types<DD>
  57. The type of user-defined functions and lambdas.
  58. </DL>
  59. <DL><DT><B>LambdaType</B> -- data of module types<DD>
  60. An alternative name for <CODE>FunctionType</CODE>.
  61. </DL>
  62. <DL><DT><B>CodeType</B> -- data of module types<DD>
  63. The type for code objects such as returned by <CODE>compile()</CODE>.
  64. </DL>
  65. <DL><DT><B>ClassType</B> -- data of module types<DD>
  66. The type of user-defined classes.
  67. </DL>
  68. <DL><DT><B>InstanceType</B> -- data of module types<DD>
  69. The type of instances of user-defined classes.
  70. </DL>
  71. <DL><DT><B>MethodType</B> -- data of module types<DD>
  72. The type of methods of user-defined class instances.
  73. </DL>
  74. <DL><DT><B>UnboundMethodType</B> -- data of module types<DD>
  75. An alternative name for <CODE>MethodType</CODE>.
  76. </DL>
  77. <DL><DT><B>BuiltinFunctionType</B> -- data of module types<DD>
  78. The type of built-in functions like <CODE>len</CODE> or <CODE>sys.exit</CODE>.
  79. </DL>
  80. <DL><DT><B>BuiltinMethodType</B> -- data of module types<DD>
  81. An alternative name for <CODE>BuiltinFunction</CODE>.
  82. </DL>
  83. <DL><DT><B>ModuleType</B> -- data of module types<DD>
  84. The type of modules.
  85. </DL>
  86. <DL><DT><B>FileType</B> -- data of module types<DD>
  87. The type of open file objects such as <CODE>sys.stdout</CODE>.
  88. </DL>
  89. <DL><DT><B>XRangeType</B> -- data of module types<DD>
  90. The type of range objects returned by <CODE>xrange()</CODE>.
  91. </DL>
  92. <DL><DT><B>TracebackType</B> -- data of module types<DD>
  93. The type of traceback objects such as found in <CODE>sys.exc_traceback</CODE>.
  94. </DL>
  95. <DL><DT><B>FrameType</B> -- data of module types<DD>
  96. The type of frame objects such as found in <CODE>tb.tb_frame</CODE> if
  97. <CODE>tb</CODE> is a traceback object.
  98. </DL>
  99.