Skip to content

Commit cab4568

Browse files
committed
OS commands, SQLite, Bytes
1 parent 3ab66cd commit cab4568

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

Diff for: README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Contents
1313
**   ** **3. Syntax:** **         ** **[`Args`](#arguments)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Duck_Type`](#duck-types)**__,__ **[`Enum`](#enum)**__,__ **[`Exception`](#exceptions)**__.__
1414
**   ** **4. System:** **        ** **[`Exit`](#exit)**__,__ **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#paths)**__,__ **[`OS_Commands`](#os-commands)**__.__
1515
**   ** **5. Data:** **             ** **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`CSV`](#csv)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`Memory_View`](#memory-view)**__,__ **[`Deque`](#deque)**__.__
16-
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Operator`](#operator)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutines`](#coroutines)**__.__
16+
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Operator`](#operator)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprogramming)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutines`](#coroutines)**__.__
1717
**   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profiling)**__,__
1818
**                                 ** **[`NumPy`](#numpy)**__,__ **[`Image`](#image)**__,__ **[`Audio`](#audio)**__,__ **[`Games`](#pygame)**__,__ **[`Data`](#pandas)**__.__
1919

@@ -1670,6 +1670,7 @@ import os, shutil
16701670
```python
16711671
os.chdir(<path>) # Changes the current working directory.
16721672
os.mkdir(<path>, mode=0o777) # Creates a directory. Mode is in octal.
1673+
os.makedirs(<path>, mode=0o777) # Creates all directories in the path.
16731674
```
16741675

16751676
```python
@@ -1850,13 +1851,14 @@ import sqlite3
18501851
### Write
18511852
```python
18521853
<conn>.execute('<query>') # Can raise a subclass of sqlite3.Error.
1853-
<conn>.commit() # Commits all transactions since last commit.
1854+
<conn>.commit() # Saves all changes since the last commit.
1855+
<conn>.rollback() # Discards all changes since the last commit.
18541856
```
18551857

18561858
#### Or:
18571859
```python
1858-
with <conn>:
1859-
<conn>.execute('<query>')
1860+
with <conn>: # Exits block with commit() or rollback(),
1861+
<conn>.execute('<query>') # depending on whether an exception occurred.
18601862
```
18611863

18621864
### Placeholders
@@ -1901,7 +1903,7 @@ Bytes
19011903
<bytes> = b'<str>' # Only accepts ASCII characters and \x00-\xff.
19021904
<int> = <bytes>[<index>] # Returns int in range from 0 to 255.
19031905
<bytes> = <bytes>[<slice>] # Returns bytes even if it has only one element.
1904-
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes object as separator.
1906+
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
19051907
```
19061908

19071909
### Encode
@@ -1950,6 +1952,7 @@ from struct import pack, unpack, iter_unpack
19501952
<tuples> = iter_unpack('<format>', <bytes>)
19511953
```
19521954

1955+
### Example
19531956
```python
19541957
>>> pack('>hhl', 1, 2, 3)
19551958
b'\x00\x01\x00\x02\x00\x00\x00\x03'
@@ -2160,8 +2163,8 @@ from inspect import signature
21602163
```
21612164

21622165

2163-
Metaprograming
2164-
--------------
2166+
Metaprogramming
2167+
---------------
21652168
**Code that generates code.**
21662169

21672170
### Type

Diff for: index.html

+12-9
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
<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_Type</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exception</a>],
239239
<strong><span class="hljs-string"><span class="hljs-string">'4. System'</span></span></strong>: [<a href="#exit">Exit</a>, <a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#paths">Path</a>, <a href="#oscommands">OS_Commands</a>],
240240
<strong><span class="hljs-string"><span class="hljs-string">'5. Data'</span></span></strong>: [<a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#csv">CSV</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">Memory_View</a>, <a href="#deque">Deque</a>],
241-
<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="#coroutines">Coroutine</a>],
241+
<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="#metaprogramming">Metaprograming</a>, <a href="#eval">Eval</a>, <a href="#coroutines">Coroutine</a>],
242242
<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="#profiling">Profile</a>,
243243
<a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>, <a href="#pygame">Games</a>, <a href="#pandas">Data</a>]
244244
}
@@ -1556,6 +1556,7 @@
15561556

15571557
<pre><code class="python language-python hljs">os.chdir(&lt;path&gt;) <span class="hljs-comment"># Changes the current working directory.</span>
15581558
os.mkdir(&lt;path&gt;, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates a directory. Mode is in octal.</span>
1559+
os.makedirs(&lt;path&gt;, mode=<span class="hljs-number">0o777</span>) <span class="hljs-comment"># Creates all directories in the path.</span>
15591560
</code></pre>
15601561
<pre><code class="python language-python hljs">shutil.copy(from, to) <span class="hljs-comment"># Copies the file. 'to' can exist or be a dir.</span>
15611562
shutil.copytree(from, to) <span class="hljs-comment"># Copies the directory. 'to' must not exist.</span>
@@ -1686,11 +1687,12 @@
16861687

16871688

16881689
<div><h3 id="write-1">Write</h3><pre><code class="python language-python hljs">&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise a subclass of sqlite3.Error.</span>
1689-
&lt;conn&gt;.commit() <span class="hljs-comment"># Commits all transactions since last commit.</span>
1690+
&lt;conn&gt;.commit() <span class="hljs-comment"># Saves all changes since the last commit.</span>
1691+
&lt;conn&gt;.rollback() <span class="hljs-comment"># Discards all changes since the last commit.</span>
16901692
</code></pre></div>
16911693

1692-
<div><h4 id="or">Or:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">with</span> &lt;conn&gt;:
1693-
&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>)
1694+
<div><h4 id="or">Or:</h4><pre><code class="python language-python hljs"><span class="hljs-keyword">with</span> &lt;conn&gt;: <span class="hljs-comment"># Exits block with commit() or rollback(),</span>
1695+
&lt;conn&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># depending on whether an exception occurred.</span>
16941696
</code></pre></div>
16951697

16961698
<div><h3 id="placeholders">Placeholders</h3><ul>
@@ -1724,7 +1726,7 @@
17241726
<div><h2 id="bytes"><a href="#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><code class="python language-python hljs">&lt;bytes&gt; = <span class="hljs-string">b'&lt;str&gt;'</span> <span class="hljs-comment"># Only accepts ASCII characters and \x00-\xff.</span>
17251727
&lt;int&gt; = &lt;bytes&gt;[&lt;index&gt;] <span class="hljs-comment"># Returns int in range from 0 to 255.</span>
17261728
&lt;bytes&gt; = &lt;bytes&gt;[&lt;slice&gt;] <span class="hljs-comment"># Returns bytes even if it has only one element.</span>
1727-
&lt;bytes&gt; = &lt;bytes&gt;.join(&lt;coll_of_bytes&gt;) <span class="hljs-comment"># Joins elements using bytes object as separator.</span>
1729+
&lt;bytes&gt; = &lt;bytes&gt;.join(&lt;coll_of_bytes&gt;) <span class="hljs-comment"># Joins elements using bytes as a separator.</span>
17281730
</code></pre></div>
17291731

17301732

@@ -1761,11 +1763,12 @@
17611763
&lt;tuple&gt; = unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
17621764
&lt;tuples&gt; = iter_unpack(<span class="hljs-string">'&lt;format&gt;'</span>, &lt;bytes&gt;)
17631765
</code></pre>
1764-
<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>pack(<span class="hljs-string">'&gt;hhl'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
1766+
<div><h3 id="example-1">Example</h3><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>pack(<span class="hljs-string">'&gt;hhl'</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
17651767
<span class="hljs-string">b'\x00\x01\x00\x02\x00\x00\x00\x03'</span>
17661768
<span class="hljs-meta">&gt;&gt;&gt; </span>unpack(<span class="hljs-string">'&gt;hhl'</span>, <span class="hljs-string">b'\x00\x01\x00\x02\x00\x00\x00\x03'</span>)
17671769
(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
1768-
</code></pre>
1770+
</code></pre></div>
1771+
17691772
<div><h3 id="format-2">Format</h3><div><h4 id="forstandardtypesizesstartformatstringwith">For standard type sizes start format string with:</h4><ul>
17701773
<li><strong><code class="python hljs"><span class="hljs-string">'='</span></code> - native byte order (usually little-endian)</strong></li>
17711774
<li><strong><code class="python hljs"><span class="hljs-string">'&lt;'</span></code> - little-endian</strong></li>
@@ -1921,7 +1924,7 @@
19211924
&lt;memb&gt; = &lt;Param&gt;.kind <span class="hljs-comment"># Member of ParameterKind enum.</span>
19221925
</code></pre></div>
19231926

1924-
<div><h2 id="metaprograming"><a href="#metaprograming" name="metaprograming">#</a>Metaprograming</h2><p><strong>Code that generates code.</strong></p><div><h3 id="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><code class="python language-python hljs">&lt;class&gt; = type(<span class="hljs-string">'&lt;class_name&gt;'</span>, &lt;parents_tuple&gt;, &lt;attributes_dict&gt;)</code></pre></div></div>
1927+
<div><h2 id="metaprogramming"><a href="#metaprogramming" name="metaprogramming">#</a>Metaprogramming</h2><p><strong>Code that generates code.</strong></p><div><h3 id="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><code class="python language-python hljs">&lt;class&gt; = type(<span class="hljs-string">'&lt;class_name&gt;'</span>, &lt;parents_tuple&gt;, &lt;attributes_dict&gt;)</code></pre></div></div>
19251928

19261929

19271930

@@ -2300,7 +2303,7 @@
23002303
right = [[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>], [<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>], [<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>]] <span class="hljs-comment"># Shape: (3, 3) &lt;- !</span>
23012304
</code></pre></div>
23022305

2303-
<div><h4 id="3ifneithernonmatchingdimensionhassize1raiseanerror">3. If neither non-matching dimension has size 1, raise an error.</h4><div><h3 id="example-1">Example</h3><div><h4 id="foreachpointreturnsindexofitsnearestpoint010608121">For each point returns index of its nearest point (<code class="python hljs">[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>] =&gt; [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>]</code>):</h4><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>points = np.array([<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>])
2306+
<div><h4 id="3ifneithernonmatchingdimensionhassize1raiseanerror">3. If neither non-matching dimension has size 1, raise an error.</h4><div><h3 id="example-2">Example</h3><div><h4 id="foreachpointreturnsindexofitsnearestpoint010608121">For each point returns index of its nearest point (<code class="python hljs">[<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>] =&gt; [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>]</code>):</h4><pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>points = np.array([<span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>])
23042307
[ <span class="hljs-number">0.1</span>, <span class="hljs-number">0.6</span>, <span class="hljs-number">0.8</span>]
23052308
<span class="hljs-meta">&gt;&gt;&gt; </span>wrapped_points = points.reshape(<span class="hljs-number">3</span>, <span class="hljs-number">1</span>)
23062309
[[ <span class="hljs-number">0.1</span>],

Diff for: parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const TOC =
2424
' <strong><span class="hljs-string">\'3. Syntax\'</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_Type</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exception</a>],\n' +
2525
' <strong><span class="hljs-string">\'4. System\'</span></strong>: [<a href="#exit">Exit</a>, <a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#paths">Path</a>, <a href="#oscommands">OS_Commands</a>],\n' +
2626
' <strong><span class="hljs-string">\'5. Data\'</span></strong>: [<a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#csv">CSV</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">Memory_View</a>, <a href="#deque">Deque</a>],\n' +
27-
' <strong><span class="hljs-string">\'6. Advanced\'</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="#coroutines">Coroutine</a>],\n' +
27+
' <strong><span class="hljs-string">\'6. Advanced\'</span></strong>: [<a href="#threading">Threading</a>, <a href="#operator">Operator</a>, <a href="#introspection">Introspection</a>, <a href="#metaprogramming">Metaprograming</a>, <a href="#eval">Eval</a>, <a href="#coroutines">Coroutine</a>],\n' +
2828
' <strong><span class="hljs-string">\'7. Libraries\'</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="#profiling">Profile</a>,\n' +
2929
' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>, <a href="#pygame">Games</a>, <a href="#pandas">Data</a>]\n' +
3030
'}\n' +

Diff for: pdf/index_for_pdf.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ <h3 id="b">B</h3>
2020
<h3 id="c">C</h3>
2121
<p><strong>cache, <a href="#lrucache">13</a></strong><br>
2222
<strong>callable, <a href="#callable">17</a></strong><br>
23-
<strong>class, <a href="#type">4</a>, <a href="#class">14</a>-<a href="#inline-2">20</a>, <a href="#metaprograming">31</a>-<a href="#metaclass">32</a></strong><br>
23+
<strong>class, <a href="#type">4</a>, <a href="#class">14</a>-<a href="#inline-2">20</a>, <a href="#metaprogramming">31</a>-<a href="#metaclass">32</a></strong><br>
2424
<strong>closure, <a href="#closure">12</a>-<a href="#decorator">13</a></strong><br>
2525
<strong>collection, <a href="#abstractbaseclasses">4</a>, <a href="#collection">18</a>, <a href="#tableofrequiredandautomaticallyavailablespecialmethods">19</a></strong><br>
2626
<strong>collections module, <a href="#dictionary">2</a>, <a href="#namedtuple">3</a>, <a href="#abstractbaseclasses">4</a>, <a href="#abcsequence">19</a>, <a href="#deque">29</a></strong><br>
@@ -85,7 +85,7 @@ <h3 id="m">M</h3>
8585
<strong>math module, <a href="#math">7</a></strong><br>
8686
<strong>memoryviews, <a href="#memoryview">29</a></strong><br>
8787
<strong>metaclass attribute, <a href="#metaclassattribute">32</a></strong><br>
88-
<strong>metaprograming, <a href="#metaprograming">31</a>-<a href="#metaclass">32</a></strong><br>
88+
<strong>metaprogramming, <a href="#metaprogramming">31</a>-<a href="#metaclass">32</a></strong><br>
8989
<strong>mysql library, <a href="#mysql">27</a></strong> </p>
9090
<h3 id="n">N</h3>
9191
<p><strong>namedtuples, <a href="#namedtuple">3</a></strong><br>
@@ -139,7 +139,7 @@ <h3 id="t">T</h3>
139139
<strong>threading module, <a href="#threading">30</a></strong><br>
140140
<strong>time module, <a href="#progressbar">34</a>, <a href="#stopwatch">36</a></strong><br>
141141
<strong>tuples, <a href="#tuple">3</a>, <a href="#abstractbaseclasses">4</a>, <a href="#otheruses">11</a></strong><br>
142-
<strong>type, <a href="#type">4</a>, <a href="#metaprograming">31</a>-<a href="#metaclass">32</a></strong> </p>
142+
<strong>type, <a href="#type">4</a>, <a href="#metaprogramming">31</a>-<a href="#metaclass">32</a></strong> </p>
143143
<h3 id="w">W</h3>
144144
<p><strong>wave module, <a href="#audio">40</a>-<a href="#writefloatsamplestowavfile">41</a></strong><br>
145145
<strong>web, <a href="#web">36</a></strong> </p>

0 commit comments

Comments
 (0)