|
215 | 215 | <strong><span class="hljs-string"><span class="hljs-string">'3. Syntax'</span></span></strong>: [<a href="#arguments">Args</a>, <a href="#inline">Inline</a>, <a href="#closure">Closure</a>, <a href="#decorator">Decorator</a>, <a href="#class">Class</a>, <a href="#ducktypes">Duck_Types</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exceptions</a>],
|
216 | 216 | <strong><span class="hljs-string"><span class="hljs-string">'4. System'</span></span></strong>: [<a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#path">Path</a>, <a href="#commandexecution">Command_Execution</a>],
|
217 | 217 | <strong><span class="hljs-string"><span class="hljs-string">'5. Data'</span></span></strong>: [<a href="#csv">CSV</a>, <a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">MemoryView</a>, <a href="#deque">Deque</a>],
|
218 |
| - <strong><span class="hljs-string"><span class="hljs-string">'6. Advanced'</span></span></strong>: [<a href="#threading">Threading</a>, <a href="#operator">Operator</a>, <a href="#eval">Eval</a>, <a href="#introspection">Introspection</a>, <a href="#metaprograming">Metaprograming</a>, <a href="#coroutine">Coroutine</a>], |
| 218 | + <strong><span class="hljs-string"><span class="hljs-string">'6. Advanced'</span></span></strong>: [<a href="#threading">Threading</a>, <a href="#operator">Operator</a>, <a href="#introspection">Introspection</a>, <a href="#metaprograming">Metaprograming</a>, <a href="#eval">Eval</a>, <a href="#coroutine">Coroutine</a>], |
219 | 219 | <strong><span class="hljs-string"><span class="hljs-string">'7. Libraries'</span></span></strong>: [<a href="#progressbar">Progress_Bar</a>, <a href="#plot">Plot</a>, <a href="#table">Table</a>, <a href="#curses">Curses</a>, <a href="#logging">Logging</a>, <a href="#scraping">Scraping</a>, <a href="#web">Web</a>, <a href="#profile">Profile</a>,
|
220 | 220 | <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]
|
221 | 221 | }
|
|
1751 | 1751 | results = executor.map(<span class="hljs-keyword">lambda</span> x, y: x + y, <span class="hljs-string">'abc'</span>, <span class="hljs-string">'123'</span>) <span class="hljs-comment"># ('a1', 'b2', 'c3')</span>
|
1752 | 1752 | </code></pre></div>
|
1753 | 1753 |
|
| 1754 | +<ul> |
| 1755 | +<li><strong>CPython interpreter can only run a single thread at the time. That is why this map() won't be faster than the standard map() unless passed function contains an I/O operation.</strong></li> |
| 1756 | +</ul> |
1754 | 1757 | <div><h2 id="operator"><a href="#operator" name="operator">#</a>Operator</h2><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
|
1755 | 1758 | <span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> eq, ne, lt, le, gt, ge
|
1756 | 1759 | <span class="hljs-keyword">from</span> operator <span class="hljs-keyword">import</span> and_, or_, not_
|
|
1764 | 1767 | LogicOp = enum.Enum(<span class="hljs-string">'LogicOp'</span>, {<span class="hljs-string">'AND'</span>: op.and_, <span class="hljs-string">'OR'</span> : op.or_})
|
1765 | 1768 | last_el = op.methodcaller(<span class="hljs-string">'pop'</span>)(<list>)
|
1766 | 1769 | </code></pre>
|
1767 |
| -<div><h2 id="eval"><a href="#eval" name="eval">#</a>Eval</h2><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> ast <span class="hljs-keyword">import</span> literal_eval |
1768 |
| -<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'1 + 2'</span>) |
1769 |
| -<span class="hljs-number">3</span> |
1770 |
| -<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'[1, 2, 3]'</span>) |
1771 |
| -[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>] |
1772 |
| -<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'abs(1)'</span>) |
1773 |
| -ValueError: malformed node or string |
1774 |
| -</code></pre></div> |
1775 |
| - |
1776 | 1770 | <div><h2 id="introspection"><a href="#introspection" name="introspection">#</a>Introspection</h2><p><strong>Inspecting code at runtime.</strong></p><div><h3 id="variables">Variables</h3><pre><code class="python language-python hljs"><list> = dir() <span class="hljs-comment"># Names of variables in current scope.</span>
|
1777 | 1771 | <dict> = locals() <span class="hljs-comment"># Dict of local variables. Also vars().</span>
|
1778 | 1772 | <dict> = globals() <span class="hljs-comment"># Dict of global variables.</span>
|
|
1854 | 1848 | | str | |
|
1855 | 1849 | +---------+-------------+
|
1856 | 1850 | </code></pre>
|
| 1851 | +<div><h2 id="eval"><a href="#eval" name="eval">#</a>Eval</h2><pre><code class="python language-python hljs"><span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> ast <span class="hljs-keyword">import</span> literal_eval |
| 1852 | +<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'1 + 2'</span>) |
| 1853 | +<span class="hljs-number">3</span> |
| 1854 | +<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'[1, 2, 3]'</span>) |
| 1855 | +[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>] |
| 1856 | +<span class="hljs-meta">>>> </span>literal_eval(<span class="hljs-string">'abs(1)'</span>) |
| 1857 | +ValueError: malformed node or string |
| 1858 | +</code></pre></div> |
| 1859 | + |
1857 | 1860 | <div><h2 id="coroutine"><a href="#coroutine" name="coroutine">#</a>Coroutine</h2><ul>
|
1858 | 1861 | <li><strong>Similar to generator, but generator pulls data through the pipe with iteration, while coroutine pushes data into the pipeline with send().</strong></li>
|
1859 | 1862 | <li><strong>Coroutines provide more powerful data routing possibilities than iterators.</strong></li>
|
|
0 commit comments