<div><h4id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> types <spanclass="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType
<div><h4id="sometypesdonothavebuiltinnamessotheymustbeimported">Some types do not have built-in names, so they must be imported:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> types <spanclass="hljs-keyword">import</span> FunctionType, MethodType, LambdaType, GeneratorType, ModuleType
</code></pre></div>
<div><h3id="abstractbaseclasses">Abstract Base Classes</h3><p><strong>Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not. ABC can also manually decide whether or not a specific class is its virtual subclass, usually based on which methods the class has implemented. For instance, Iterable ABC looks for method iter() while Collection ABC looks for methods iter(), contains() and len().</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span><spanclass="hljs-keyword">from</span> collections.abc <spanclass="hljs-keyword">import</span> Sequence, Collection, Iterable
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'skipinitialspace'</span></code> - Whether whitespace after delimiter gets stripped.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'lineterminator'</span></code> - Specifies how writer terminates rows.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'quoting'</span></code> - Controls the amount of quoting: 0 - as necessary, 1 - all.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'escapechar'</span></code> - Character for escaping 'quotechar' if 'doublequote' is False.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'escapechar'</span></code> - Character for escaping quotechars if doublequote is False.</strong></li>
<dict> = vars(<object>) <spanclass="hljs-comment"># Dict of writable attributes. Also <obj>.__dict__.</span>
<bool> = hasattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Checks if getattr() raises an AttributeError.</span>
value = getattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Raises AttributeError if attribute is missing.</span>
setattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>, value) <spanclass="hljs-comment"># Only works on objects with __dict__ attribute.</span>
delattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Equivalent to `del <object>.<attr_name>`.</span>
setattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>, value) <spanclass="hljs-comment"># Only works on objects with '__dict__' attribute.</span>
delattr(<object>, <spanclass="hljs-string">'<attr_name>'</span>) <spanclass="hljs-comment"># Same. Also `del <object>.<attr_name>`.</span>
<memb> = <Param>.kind <spanclass="hljs-comment"># Member of ParameterKind enum.</span>
</code></pre></div>
<div><h2id="metaprogramming"><ahref="#metaprogramming"name="metaprogramming">#</a>Metaprogramming</h2><p><strong>Code that generates code.</strong></p><div><h3id="type-1">Type</h3><p><strong>Type is the root class. If only passed an object it returns its type (class). Otherwise it creates a new class.</strong></p><pre><codeclass="python language-python hljs"><class> = type(<spanclass="hljs-string">'<class_name>'</span>, <parents_tuple>, <attributes_dict>)</code></pre></div></div>
<div><h2id="metaprogramming"><ahref="#metaprogramming"name="metaprogramming">#</a>Metaprogramming</h2><p><strong>Code that generates code.</strong></p><div><h3id="type-1">Type</h3><p><strong>Type is the root class. If only passed an object it returns its type (class). Otherwise it creates a new class.</strong></p><pre><codeclass="python language-python hljs"><class> = type(<spanclass="hljs-string">'<class_name>'</span>, <tuple_of_parents>, <dict_of_class_attributes>)</code></pre></div></div>