<div><h3id="timezone">Timezone</h3><pre><codeclass="python language-python apache hljs"><tzinfo> = UTC <spanclass="hljs-comment"># UTC timezone. London without DST.</span>
<tzinfo> = tzlocal() <spanclass="hljs-comment"># Local timezone. Also gettz().</span>
<tzinfo> = gettz(<spanclass="hljs-string">'<Continent>/<City>'</span>) <spanclass="hljs-comment"># 'Continent/City_Name' timezone or None.</span>
<DTa> = <DT>.astimezone(<tzinfo>) <spanclass="hljs-comment"># Datetime, converted to passed timezone.</span>
<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) <spanclass="hljs-comment"># Unconverted object with new timezone.</span>
<DTa> = <DT>.astimezone(<tzinfo>) <spanclass="hljs-comment"># Datetime, converted to the passed timezone.</span>
<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) <spanclass="hljs-comment"># Unconverted object with a new timezone.</span>
</code></pre></div>
<div><h3id="encode">Encode</h3><pre><codeclass="python language-python apache hljs"><D/T/DT> = D/T/DT.fromisoformat(<spanclass="hljs-string">'<iso>'</span>) <spanclass="hljs-comment"># Object from ISO string. Raises ValueError.</span>
<DT> = DT.strptime(<str>, <spanclass="hljs-string">'<format>'</span>) <spanclass="hljs-comment"># Datetime from str, according to format.</span>
<D/DTn> = D/DT.fromordinal(<int>) <spanclass="hljs-comment"># D/DTn from days since Christ, at midnight.</span>
<D/DTn> = D/DT.fromordinal(<int>) <spanclass="hljs-comment"># D/DTn from days since the Gregorian NYE 1.</span>
<DTn> = DT.fromtimestamp(<real>) <spanclass="hljs-comment"># Local time DTn from seconds since the Epoch.</span>
<DTa> = DT.fromtimestamp(<real>, <tz.>) <spanclass="hljs-comment"># Aware datetime from seconds since the Epoch.</span>
<div><h3id="thread">Thread</h3><pre><codeclass="python language-python hljs"><Thread> = Thread(target=<function>) <spanclass="hljs-comment"># Use `args=<collection>` to set arguments.</span>
<Thread>.start() <spanclass="hljs-comment"># Starts the thread.</span>
<bool> = <Thread>.is_alive() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<Thread>.join() <spanclass="hljs-comment"># Waits for thread to finish.</span>
<div><h3id="thread">Thread</h3><pre><codeclass="python language-python hljs"><Thread> = Thread(target=<function>) <spanclass="hljs-comment"># Use `args=<collection>` to set arguments.</span>
<Thread>.start() <spanclass="hljs-comment"># Starts the thread.</span>
<bool> = <Thread>.is_alive() <spanclass="hljs-comment"># Checks if thread has finished executing.</span>
<Thread>.join() <spanclass="hljs-comment"># Waits for thread to finish.</span>
</code></pre></div>
<ul>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'kwargs=<dict>'</span></code> to pass keyword arguments to the function.</strong></li>
<li><strong>Use <codeclass="python hljs"><spanclass="hljs-string">'daemon=True'</span></code>, or the program will not be able to exit while the thread is alive.</strong></li>
</ul>
<div><h3id="lock">Lock</h3><pre><codeclass="python language-python hljs"><lock> = RLock() <spanclass="hljs-comment"># Lock that can only be released by the owner.</span>
<lock>.acquire() <spanclass="hljs-comment"># Waits for lock to be available.</span>
<lock>.release() <spanclass="hljs-comment"># Makes lock available again.</span>
<div><h3id="lock">Lock</h3><pre><codeclass="python language-python hljs"><lock> = RLock() <spanclass="hljs-comment"># Lock that can only be released by the owner.</span>
<lock>.acquire() <spanclass="hljs-comment"># Waits for lock to be available.</span>
<lock>.release() <spanclass="hljs-comment"># Makes lock available again.</span>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired by 'value' threads.</span>
<Event> = Event() <spanclass="hljs-comment"># Method wait() blocks until set() is called.</span>
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Method wait() blocks until it's called n_times.</span>
<div><h3id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><codeclass="python language-python hljs"><Semaphore> = Semaphore(value=<spanclass="hljs-number">1</span>) <spanclass="hljs-comment"># Lock that can be acquired by 'value' threads.</span>
<Event> = Event() <spanclass="hljs-comment"># Method wait() blocks until set() is called.</span>
<Barrier> = Barrier(n_times) <spanclass="hljs-comment"># Wait() blocks until it's called n_times.</span>
</code></pre></div>
<div><h3id="threadpoolexecutor">Thread Pool Executor</h3><p><strong>Object that manages thread execution.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> concurrent.futures <spanclass="hljs-keyword">import</span> ThreadPoolExecutor
</code></pre></div>
<pre><codeclass="python language-python hljs"><Exec> = ThreadPoolExecutor([max_workers]) <spanclass="hljs-comment"># Use max_workers to limit the number of threads.</span>
<Exec>.shutdown(wait=<spanclass="hljs-keyword">True</span>) <spanclass="hljs-comment"># Or: `with ThreadPoolExecutor() as executor: …`</span>
<pre><codeclass="python language-python hljs"><Queue>.put(<el>) <spanclass="hljs-comment"># Blocks until queue stops being full.</span>
<Queue>.put_nowait(<el>) <spanclass="hljs-comment"># Raises queue.Full exception if full.</span>
<el> = <Queue>.get() <spanclass="hljs-comment"># Blocks until queue stops being empty.</span>
<el> = <Queue>.get_nowait() <spanclass="hljs-comment"># Raises queue.Empty exception if empty.</span>
<pre><codeclass="python language-python hljs"><Queue>.put(<el>) <spanclass="hljs-comment"># Blocks until queue stops being full.</span>
<Queue>.put_nowait(<el>) <spanclass="hljs-comment"># Raises queue.Full exception if full.</span>
<el> = <Queue>.get() <spanclass="hljs-comment"># Blocks until queue stops being empty.</span>
<el> = <Queue>.get_nowait() <spanclass="hljs-comment"># Raises queue.Empty exception if empty.</span>
</code></pre>
<div><h2id="operator"><ahref="#operator"name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">from</span> operator <spanclass="hljs-keyword">import</span> add, sub, mul, truediv, floordiv, mod, pow, neg, abs
<spanclass="hljs-keyword">from</span> operator <spanclass="hljs-keyword">import</span> eq, ne, lt, le, gt, ge
xxxxxxxxxx