diff --git a/README.md b/README.md index e63f1c4..c7df9d0 100644 --- a/README.md +++ b/README.md @@ -513,9 +513,9 @@ from statistics import mean, median, variance, stdev, pvariance, pstdev ```python from random import random, randint, choice, shuffle, gauss, seed -<float> = random() -<int> = randint(from_inclusive, to_inclusive) -<el> = choice(<list>) +<float> = random() # A float inside [0, 1). +<int> = randint(from_inc, to_inc) # An int inside [from_inc, to_inc]. +<el> = choice(<list>) # Keeps the list intact. ``` ### Bin, Hex @@ -614,15 +614,15 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary <tzinfo> = UTC # UTC timezone. London without DST. <tzinfo> = tzlocal() # Local timezone. Also gettz(). <tzinfo> = gettz('<Continent>/<City>') # 'Continent/City_Name' timezone or None. -<DTa> = <DT>.astimezone(<tzinfo>) # Datetime, converted to passed timezone. -<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) # Unconverted object with new timezone. +<DTa> = <DT>.astimezone(<tzinfo>) # Datetime, converted to the passed timezone. +<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) # Unconverted object with a new timezone. ``` ### Encode ```python <D/T/DT> = D/T/DT.fromisoformat('<iso>') # Object from ISO string. Raises ValueError. <DT> = DT.strptime(<str>, '<format>') # Datetime from str, according to format. -<D/DTn> = D/DT.fromordinal(<int>) # D/DTn from days since Christ, at midnight. +<D/DTn> = D/DT.fromordinal(<int>) # D/DTn from days since the Gregorian NYE 1. <DTn> = DT.fromtimestamp(<real>) # Local time DTn from seconds since the Epoch. <DTa> = DT.fromtimestamp(<real>, <tz.>) # Aware datetime from seconds since the Epoch. ``` @@ -633,7 +633,7 @@ from dateutil.tz import UTC, tzlocal, gettz, datetime_exists, resolve_imaginary ```python <str> = <D/T/DT>.isoformat(sep='T') # Also timespec='auto/hours/minutes/seconds'. <str> = <D/T/DT>.strftime('<format>') # Custom string representation. -<int> = <D/DT>.toordinal() # Days since Christ, ignoring time and tz. +<int> = <D/DT>.toordinal() # Days since Gregorian NYE 1, ignoring time and tz. <float> = <DTn>.timestamp() # Seconds since the Epoch, from DTn in local tz. <float> = <DTa>.timestamp() # Seconds since the Epoch, from DTa. ``` @@ -2050,19 +2050,19 @@ from threading import Thread, RLock, Semaphore, Event, Barrier ### Thread ```python -<Thread> = Thread(target=<function>) # Use `args=<collection>` to set arguments. -<Thread>.start() # Starts the thread. -<bool> = <Thread>.is_alive() # Checks if thread has finished executing. -<Thread>.join() # Waits for thread to finish. +<Thread> = Thread(target=<function>) # Use `args=<collection>` to set arguments. +<Thread>.start() # Starts the thread. +<bool> = <Thread>.is_alive() # Checks if thread has finished executing. +<Thread>.join() # Waits for thread to finish. ``` * **Use `'kwargs=<dict>'` to pass keyword arguments to the function.** * **Use `'daemon=True'`, or the program will not be able to exit while the thread is alive.** ### Lock ```python -<lock> = RLock() # Lock that can only be released by the owner. -<lock>.acquire() # Waits for lock to be available. -<lock>.release() # Makes lock available again. +<lock> = RLock() # Lock that can only be released by the owner. +<lock>.acquire() # Waits for lock to be available. +<lock>.release() # Makes lock available again. ``` #### Or: @@ -2074,9 +2074,9 @@ with lock: ### Semaphore, Event, Barrier ```python -<Semaphore> = Semaphore(value=1) # Lock that can be acquired by 'value' threads. -<Event> = Event() # Method wait() blocks until set() is called. -<Barrier> = Barrier(n_times) # Method wait() blocks until it's called n_times. +<Semaphore> = Semaphore(value=1) # Lock that can be acquired by 'value' threads. +<Event> = Event() # Method wait() blocks until set() is called. +<Barrier> = Barrier(n_times) # Wait() blocks until it's called n_times. ``` ### Thread Pool Executor @@ -2086,15 +2086,15 @@ from concurrent.futures import ThreadPoolExecutor ``` ```python -<Exec> = ThreadPoolExecutor([max_workers]) # Use max_workers to limit the number of threads. -<Exec>.shutdown(wait=True) # Or: `with ThreadPoolExecutor() as executor: …` +<Exec> = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as <name>: …` +<Exec>.shutdown(wait=True) # Cleans-up the resources associated with Exec. ``` ```python -<iter> = <Exec>.map(<func>, <args_1>, ...) # A multithreaded and non-lazy map(). -<Futr> = <Exec>.submit(<func>, <arg_1>, ...) # Starts a thread and returns its Future object. -<bool> = <Futr>.done() # Checks if thread has finished executing. -<obj> = <Futr>.result() # Waits for thread to finish and returns result. +<iter> = <Exec>.map(<func>, <args_1>, ...) # A multithreaded and non-lazy map(). +<Futr> = <Exec>.submit(<func>, <arg_1>, ...) # Starts a thread and returns its Future object. +<bool> = <Futr>.done() # Checks if the thread has finished executing. +<obj> = <Futr>.result() # Waits for thread to finish and returns result. ``` ### Queue @@ -2105,10 +2105,10 @@ from queue import Queue ``` ```python -<Queue>.put(<el>) # Blocks until queue stops being full. -<Queue>.put_nowait(<el>) # Raises queue.Full exception if full. -<el> = <Queue>.get() # Blocks until queue stops being empty. -<el> = <Queue>.get_nowait() # Raises queue.Empty exception if empty. +<Queue>.put(<el>) # Blocks until queue stops being full. +<Queue>.put_nowait(<el>) # Raises queue.Full exception if full. +<el> = <Queue>.get() # Blocks until queue stops being empty. +<el> = <Queue>.get_nowait() # Raises queue.Empty exception if empty. ``` @@ -2158,7 +2158,7 @@ delattr(<object>, '<attr_name>') # Equivalent to `del <object>.<attr_n ### Parameters ```python from inspect import signature -<Sig> = signature(<function>) # Signature object of the function. +<Sig> = signature(<function>) # Function's Signature object. <dict> = <Sig>.parameters # Dict of function's Parameter objects. <str> = <Param>.name # Parameter's name. <memb> = <Param>.kind # Member of ParameterKind enum. diff --git a/index.html b/index.html index e42ebc3..ec84c42 100644 --- a/index.html +++ b/index.html @@ -615,9 +615,9 @@ to_exclusive = <range>.stop <div><h3 id="random">Random</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> random <span class="hljs-keyword">import</span> random, randint, choice, shuffle, gauss, seed -<float> = random() -<int> = randint(from_inclusive, to_inclusive) -<el> = choice(<list>) +<float> = random() <span class="hljs-comment"># A float inside [0, 1).</span> +<int> = randint(from_inc, to_inc) <span class="hljs-comment"># An int inside [from_inc, to_inc].</span> +<el> = choice(<list>) <span class="hljs-comment"># Keeps the list intact.</span> </code></pre></div> <div><h3 id="binhex">Bin, Hex</h3><pre><code class="python language-python hljs"><int> = ±<span class="hljs-number">0</span>b<bin> <span class="hljs-comment"># Or: ±0x<hex></span> @@ -694,13 +694,13 @@ to_exclusive = <range>.stop <div><h3 id="timezone">Timezone</h3><pre><code class="python language-python apache hljs"><tzinfo> = UTC <span class="hljs-comment"># UTC timezone. London without DST.</span> <tzinfo> = tzlocal() <span class="hljs-comment"># Local timezone. Also gettz().</span> <tzinfo> = gettz(<span class="hljs-string">'<Continent>/<City>'</span>) <span class="hljs-comment"># 'Continent/City_Name' timezone or None.</span> -<DTa> = <DT>.astimezone(<tzinfo>) <span class="hljs-comment"># Datetime, converted to passed timezone.</span> -<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) <span class="hljs-comment"># Unconverted object with new timezone.</span> +<DTa> = <DT>.astimezone(<tzinfo>) <span class="hljs-comment"># Datetime, converted to the passed timezone.</span> +<Ta/DTa> = <T/DT>.replace(tzinfo=<tzinfo>) <span class="hljs-comment"># Unconverted object with a new timezone.</span> </code></pre></div> <div><h3 id="encode">Encode</h3><pre><code class="python language-python apache hljs"><D/T/DT> = D/T/DT.fromisoformat(<span class="hljs-string">'<iso>'</span>) <span class="hljs-comment"># Object from ISO string. Raises ValueError.</span> <DT> = DT.strptime(<str>, <span class="hljs-string">'<format>'</span>) <span class="hljs-comment"># Datetime from str, according to format.</span> -<D/DTn> = D/DT.fromordinal(<int>) <span class="hljs-comment"># D/DTn from days since Christ, at midnight.</span> +<D/DTn> = D/DT.fromordinal(<int>) <span class="hljs-comment"># D/DTn from days since the Gregorian NYE 1.</span> <DTn> = DT.fromtimestamp(<real>) <span class="hljs-comment"># Local time DTn from seconds since the Epoch.</span> <DTa> = DT.fromtimestamp(<real>, <tz.>) <span class="hljs-comment"># Aware datetime from seconds since the Epoch.</span> </code></pre></div> @@ -711,7 +711,7 @@ to_exclusive = <range>.stop </ul> <div><h3 id="decode">Decode</h3><pre><code class="python language-python hljs"><str> = <D/T/DT>.isoformat(sep=<span class="hljs-string">'T'</span>) <span class="hljs-comment"># Also timespec='auto/hours/minutes/seconds'.</span> <str> = <D/T/DT>.strftime(<span class="hljs-string">'<format>'</span>) <span class="hljs-comment"># Custom string representation.</span> -<int> = <D/DT>.toordinal() <span class="hljs-comment"># Days since Christ, ignoring time and tz.</span> +<int> = <D/DT>.toordinal() <span class="hljs-comment"># Days since Gregorian NYE 1, ignoring time and tz.</span> <float> = <DTn>.timestamp() <span class="hljs-comment"># Seconds since the Epoch, from DTn in local tz.</span> <float> = <DTa>.timestamp() <span class="hljs-comment"># Seconds since the Epoch, from DTa.</span> </code></pre></div> @@ -1835,19 +1835,19 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs- </code></pre></div> -<div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs"><Thread> = Thread(target=<function>) <span class="hljs-comment"># Use `args=<collection>` to set arguments.</span> -<Thread>.start() <span class="hljs-comment"># Starts the thread.</span> -<bool> = <Thread>.is_alive() <span class="hljs-comment"># Checks if thread has finished executing.</span> -<Thread>.join() <span class="hljs-comment"># Waits for thread to finish.</span> +<div><h3 id="thread">Thread</h3><pre><code class="python language-python hljs"><Thread> = Thread(target=<function>) <span class="hljs-comment"># Use `args=<collection>` to set arguments.</span> +<Thread>.start() <span class="hljs-comment"># Starts the thread.</span> +<bool> = <Thread>.is_alive() <span class="hljs-comment"># Checks if thread has finished executing.</span> +<Thread>.join() <span class="hljs-comment"># Waits for thread to finish.</span> </code></pre></div> <ul> <li><strong>Use <code class="python hljs"><span class="hljs-string">'kwargs=<dict>'</span></code> to pass keyword arguments to the function.</strong></li> <li><strong>Use <code class="python hljs"><span class="hljs-string">'daemon=True'</span></code>, or the program will not be able to exit while the thread is alive.</strong></li> </ul> -<div><h3 id="lock">Lock</h3><pre><code class="python language-python hljs"><lock> = RLock() <span class="hljs-comment"># Lock that can only be released by the owner.</span> -<lock>.acquire() <span class="hljs-comment"># Waits for lock to be available.</span> -<lock>.release() <span class="hljs-comment"># Makes lock available again.</span> +<div><h3 id="lock">Lock</h3><pre><code class="python language-python hljs"><lock> = RLock() <span class="hljs-comment"># Lock that can only be released by the owner.</span> +<lock>.acquire() <span class="hljs-comment"># Waits for lock to be available.</span> +<lock>.release() <span class="hljs-comment"># Makes lock available again.</span> </code></pre></div> <div><h4 id="or-1">Or:</h4><pre><code class="python language-python hljs">lock = RLock() @@ -1855,32 +1855,32 @@ CompletedProcess(args=[<span class="hljs-string">'bc'</span>, <span class="hljs- ... </code></pre></div> -<div><h3 id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><code class="python language-python hljs"><Semaphore> = Semaphore(value=<span class="hljs-number">1</span>) <span class="hljs-comment"># Lock that can be acquired by 'value' threads.</span> -<Event> = Event() <span class="hljs-comment"># Method wait() blocks until set() is called.</span> -<Barrier> = Barrier(n_times) <span class="hljs-comment"># Method wait() blocks until it's called n_times.</span> +<div><h3 id="semaphoreeventbarrier">Semaphore, Event, Barrier</h3><pre><code class="python language-python hljs"><Semaphore> = Semaphore(value=<span class="hljs-number">1</span>) <span class="hljs-comment"># Lock that can be acquired by 'value' threads.</span> +<Event> = Event() <span class="hljs-comment"># Method wait() blocks until set() is called.</span> +<Barrier> = Barrier(n_times) <span class="hljs-comment"># Wait() blocks until it's called n_times.</span> </code></pre></div> <div><h3 id="threadpoolexecutor">Thread Pool Executor</h3><p><strong>Object that manages thread execution.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> concurrent.futures <span class="hljs-keyword">import</span> ThreadPoolExecutor </code></pre></div> -<pre><code class="python language-python hljs"><Exec> = ThreadPoolExecutor([max_workers]) <span class="hljs-comment"># Use max_workers to limit the number of threads.</span> -<Exec>.shutdown(wait=<span class="hljs-keyword">True</span>) <span class="hljs-comment"># Or: `with ThreadPoolExecutor() as executor: …`</span> +<pre><code class="python language-python hljs"><Exec> = ThreadPoolExecutor(max_workers=<span class="hljs-keyword">None</span>) <span class="hljs-comment"># Or: `with ThreadPoolExecutor() as <name>: …`</span> +<Exec>.shutdown(wait=<span class="hljs-keyword">True</span>) <span class="hljs-comment"># Cleans-up the resources associated with Exec.</span> </code></pre> -<pre><code class="python language-python hljs"><iter> = <Exec>.map(<func>, <args_1>, ...) <span class="hljs-comment"># A multithreaded and non-lazy map().</span> -<Futr> = <Exec>.submit(<func>, <arg_1>, ...) <span class="hljs-comment"># Starts a thread and returns its Future object.</span> -<bool> = <Futr>.done() <span class="hljs-comment"># Checks if thread has finished executing.</span> -<obj> = <Futr>.result() <span class="hljs-comment"># Waits for thread to finish and returns result.</span> +<pre><code class="python language-python hljs"><iter> = <Exec>.map(<func>, <args_1>, ...) <span class="hljs-comment"># A multithreaded and non-lazy map().</span> +<Futr> = <Exec>.submit(<func>, <arg_1>, ...) <span class="hljs-comment"># Starts a thread and returns its Future object.</span> +<bool> = <Futr>.done() <span class="hljs-comment"># Checks if the thread has finished executing.</span> +<obj> = <Futr>.result() <span class="hljs-comment"># Waits for thread to finish and returns result.</span> </code></pre> <div><h3 id="queue">Queue</h3><p><strong>A thread-safe FIFO queue. For LIFO queue use LifoQueue.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> queue <span class="hljs-keyword">import</span> Queue <Queue> = Queue(maxsize=<span class="hljs-number">0</span>) </code></pre></div> -<pre><code class="python language-python hljs"><Queue>.put(<el>) <span class="hljs-comment"># Blocks until queue stops being full.</span> -<Queue>.put_nowait(<el>) <span class="hljs-comment"># Raises queue.Full exception if full.</span> -<el> = <Queue>.get() <span class="hljs-comment"># Blocks until queue stops being empty.</span> -<el> = <Queue>.get_nowait() <span class="hljs-comment"># Raises queue.Empty exception if empty.</span> +<pre><code class="python language-python hljs"><Queue>.put(<el>) <span class="hljs-comment"># Blocks until queue stops being full.</span> +<Queue>.put_nowait(<el>) <span class="hljs-comment"># Raises queue.Full exception if full.</span> +<el> = <Queue>.get() <span class="hljs-comment"># Blocks until queue stops being empty.</span> +<el> = <Queue>.get_nowait() <span class="hljs-comment"># Raises queue.Empty exception if empty.</span> </code></pre> <div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><p><strong>Module of functions that provide the functionality of operators.</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> add, sub, mul, truediv, floordiv, mod, pow, neg, abs <span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> eq, ne, lt, le, gt, ge @@ -1914,7 +1914,7 @@ delattr(<object>, <span class="hljs-string">'<attr_name>'</span>) </code></pre></div> <div><h3 id="parameters-1">Parameters</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> inspect <span class="hljs-keyword">import</span> signature -<Sig> = signature(<function>) <span class="hljs-comment"># Signature object of the function.</span> +<Sig> = signature(<function>) <span class="hljs-comment"># Function's Signature object.</span> <dict> = <Sig>.parameters <span class="hljs-comment"># Dict of function's Parameter objects.</span> <str> = <Param>.name <span class="hljs-comment"># Parameter's name.</span> <memb> = <Param>.kind <span class="hljs-comment"># Member of ParameterKind enum.</span>