<div><h3id="write-1">Write</h3><pre><codeclass="python language-python hljs"><conn>.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
<conn>.commit() <spanclass="hljs-comment"># Commits all transactions since last commit.</span>
<conn>.commit() <spanclass="hljs-comment"># Saves all changes since the last commit.</span>
<conn>.rollback() <spanclass="hljs-comment"># Discards all changes since the last commit.</span>
<div><h4id="or">Or:</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">with</span><conn>:<spanclass="hljs-comment"># Exits block with commit() or rollback(),</span>
<conn>.execute(<spanclass="hljs-string">'<query>'</span>)<spanclass="hljs-comment"># depending on whether an exception occurred.</span>
<div><h2id="bytes"><ahref="#bytes"name="bytes">#</a>Bytes</h2><p><strong>Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.</strong></p><pre><codeclass="python language-python hljs"><bytes> = <spanclass="hljs-string">b'<str>'</span><spanclass="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
<int> = <bytes>[<index>] <spanclass="hljs-comment"># Returns int in range from 0 to 255.</span>
<bytes> = <bytes>[<slice>] <spanclass="hljs-comment"># Returns bytes even if it has only one element.</span>
<bytes> = <bytes>.join(<coll_of_bytes>) <spanclass="hljs-comment"># Joins elements using bytes object as separator.</span>
<bytes> = <bytes>.join(<coll_of_bytes>) <spanclass="hljs-comment"># Joins elements using bytes as a separator.</span>
<memb> = <Param>.kind <spanclass="hljs-comment"># Member of ParameterKind enum.</span>
</code></pre></div>
<div><h2id="metaprograming"><ahref="#metaprograming"name="metaprograming">#</a>Metaprograming</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>, <parents_tuple>, <attributes_dict>)</code></pre></div></div>
<div><h4id="3ifneithernonmatchingdimensionhassize1raiseanerror">3. If neither non-matching dimension has size 1, raise an error.</h4><div><h3id="example-1">Example</h3><div><h4id="foreachpointreturnsindexofitsnearestpoint010608121">For each point returns index of its nearest point (<codeclass="python hljs">[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>] => [<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>, <spanclass="hljs-number">1</span>]</code>):</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>points = np.array([<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>])
<div><h4id="3ifneithernonmatchingdimensionhassize1raiseanerror">3. If neither non-matching dimension has size 1, raise an error.</h4><div><h3id="example-2">Example</h3><div><h4id="foreachpointreturnsindexofitsnearestpoint010608121">For each point returns index of its nearest point (<codeclass="python hljs">[<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>] => [<spanclass="hljs-number">1</span>, <spanclass="hljs-number">2</span>, <spanclass="hljs-number">1</span>]</code>):</h4><pre><codeclass="python language-python hljs"><spanclass="hljs-meta">>>></span>points = np.array([<spanclass="hljs-number">0.1</span>, <spanclass="hljs-number">0.6</span>, <spanclass="hljs-number">0.8</span>])
xxxxxxxxxx