Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's generally not very useful to actually instantiate the types in the <code>types</code> module. Their purpose is to be used in <code>isinstance()</code> calls, and some of them can't be instantiated at all (for example <code>types.GeneratorType</code>).</p> <p>If it's just curiosity, have a look at the documentation available in the interactive interpreter, for example</p> <pre><code>help(types.CodeType) </code></pre> <p>If you really think you <em>need</em> to instanciate these types, I would be curious to hear an example use case :)</p> <p><strong>Edit</strong>: Here is a complete categorised list of the types in the <code>types</code> module for Python 2.5 to 2.7. If multiple types are put on the same line, they are just aliases for the same type.</p> <ul> <li><p>10 types cannot be instantiated at all:</p> <pre><code>BuiltinFunctionType, BuiltinMethodType DictProxyType EllipsisType FrameType GeneratorType GetSetDescriptorType MemberDescriptorType NoneType NotImplementedType TracebackType </code></pre></li> <li><p>16 types are aliases for built-in names:</p> <pre><code>BooleanType bool BufferType buffer ComplexType complex DictType, DictionaryType dict FileType file FloatType float IntType int ListType list LongType long ObjectType object SliceType slice TupleType tuple TypeType type StringType str UnicodeType unicode XRangeType xrange </code></pre> <p>To instantiate those, it is preferable to use the built-in name.</p></li> <li><p>The remaining 6 types have useful docstrings:</p> <pre><code>ClassType CodeType FunctionType, LambdaType InstanceType MethodType, UnboundMethodType ModuleType </code></pre> <p><code>ClassType</code> and <code>InstanceType</code> can be considered obsolete, since they refer to old-style classes.</p></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload