Skip to content

Commit f252b59

Browse files
committed
CSV, SQLite
1 parent e2b2d70 commit f252b59

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,15 +1775,15 @@ import csv
17751775

17761776
### Read
17771777
```python
1778-
<reader> = csv.reader(<file>, dialect='excel', delimiter=',')
1778+
<reader> = csv.reader(<file>) # Also: `dialect='excel', delimiter=','`.
17791779
<list> = next(<reader>) # Returns next row as a list of strings.
17801780
<list> = list(<reader>) # Returns list of remaining rows.
17811781
```
17821782
* **File must be opened with `'newline=""'` argument, or newlines embedded inside quoted fields will not be interpreted correctly!**
17831783

17841784
### Write
17851785
```python
1786-
<writer> = csv.writer(<file>, dialect='excel', delimiter=',')
1786+
<writer> = csv.writer(<file>) # Also: `dialect='excel', delimiter=','`.
17871787
<writer>.writerow(<collection>) # Encodes objects using `str(<el>)`.
17881788
<writer>.writerows(<coll_of_coll>) # Appends multiple rows.
17891789
```
@@ -1889,8 +1889,8 @@ db.executemany('<query>', <coll_of_above>) # Runs execute() many times.
18891889
```python
18901890
# $ pip3 install mysql-connector
18911891
from mysql import connector
1892-
db = connector.connect(host=<str>, user=<str>, password=<str>, database=<str>)
1893-
<cursor> = db.cursor()
1892+
db = connector.connect(host=<str>, …) # `user=<str>, password=<str>, database=<str>`.
1893+
<cursor> = db.cursor() # Only cursor has execute method.
18941894
<cursor>.execute('<query>') # Can raise a subclass of connector.Error.
18951895
<cursor>.execute('<query>', <list/tuple>) # Replaces '%s's in query with values.
18961896
<cursor>.execute('<query>', <dict/namedtuple>) # Replaces '%(<key>)s's with values.
@@ -1912,15 +1912,15 @@ Bytes
19121912
```python
19131913
<bytes> = bytes(<coll_of_ints>) # Ints must be in range from 0 to 255.
19141914
<bytes> = bytes(<str>, 'utf-8') # Or: <str>.encode('utf-8')
1915-
<bytes> = <int>.to_bytes(n_bytes, …) # `byteorder='big/little', signed=False`
1915+
<bytes> = <int>.to_bytes(n_bytes, …) # `byteorder='big/little', signed=False`.
19161916
<bytes> = bytes.fromhex('<hex>') # Hex numbers can be separated by spaces.
19171917
```
19181918

19191919
### Decode
19201920
```python
19211921
<list> = list(<bytes>) # Returns ints in range from 0 to 255.
19221922
<str> = str(<bytes>, 'utf-8') # Or: <bytes>.decode('utf-8')
1923-
<int> = int.from_bytes(<bytes>, …) # `byteorder='big/little', signed=False`
1923+
<int> = int.from_bytes(<bytes>, …) # `byteorder='big/little', signed=False`.
19241924
'<hex>' = <bytes>.hex() # Returns a string of hexadecimal numbers.
19251925
```
19261926

@@ -2016,7 +2016,7 @@ Memory View
20162016
```python
20172017
<list> = list(<mview>) # Returns list of ints or floats.
20182018
<str> = str(<mview>, 'utf-8') # Treats mview as a bytes object.
2019-
<int> = int.from_bytes(<mview>, …) # `byteorder='big/little', signed=False`
2019+
<int> = int.from_bytes(<mview>, …) # `byteorder='big/little', signed=False`.
20202020
'<hex>' = <mview>.hex() # Treats mview as a bytes object.
20212021
```
20222022

index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,15 +1590,15 @@
15901590
</code></pre></div>
15911591

15921592

1593-
<div><h3 id="read">Read</h3><pre><code class="python language-python hljs">&lt;reader&gt; = csv.reader(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
1593+
<div><h3 id="read">Read</h3><pre><code class="python language-python hljs">&lt;reader&gt; = csv.reader(&lt;file&gt;) <span class="hljs-comment"># Also: `dialect='excel', delimiter=','`.</span>
15941594
&lt;list&gt; = next(&lt;reader&gt;) <span class="hljs-comment"># Returns next row as a list of strings.</span>
15951595
&lt;list&gt; = list(&lt;reader&gt;) <span class="hljs-comment"># Returns list of remaining rows.</span>
15961596
</code></pre></div>
15971597

15981598
<ul>
15991599
<li><strong>File must be opened with <code class="python hljs"><span class="hljs-string">'newline=""'</span></code> argument, or newlines embedded inside quoted fields will not be interpreted correctly!</strong></li>
16001600
</ul>
1601-
<div><h3 id="write">Write</h3><pre><code class="python language-python hljs">&lt;writer&gt; = csv.writer(&lt;file&gt;, dialect=<span class="hljs-string">'excel'</span>, delimiter=<span class="hljs-string">','</span>)
1601+
<div><h3 id="write">Write</h3><pre><code class="python language-python hljs">&lt;writer&gt; = csv.writer(&lt;file&gt;) <span class="hljs-comment"># Also: `dialect='excel', delimiter=','`.</span>
16021602
&lt;writer&gt;.writerow(&lt;collection&gt;) <span class="hljs-comment"># Encodes objects using `str(&lt;el&gt;)`.</span>
16031603
&lt;writer&gt;.writerows(&lt;coll_of_coll&gt;) <span class="hljs-comment"># Appends multiple rows.</span>
16041604
</code></pre></div>
@@ -1684,8 +1684,8 @@
16841684

16851685
<div><h3 id="mysql">MySQL</h3><p><strong>Has a very similar interface, with differences listed below.</strong></p><pre><code class="python language-python hljs"><span class="hljs-comment"># $ pip3 install mysql-connector</span>
16861686
<span class="hljs-keyword">from</span> mysql <span class="hljs-keyword">import</span> connector
1687-
db = connector.connect(host=&lt;str&gt;, user=&lt;str&gt;, password=&lt;str&gt;, database=&lt;str&gt;)
1688-
&lt;cursor&gt; = db.cursor()
1687+
db = connector.connect(host=&lt;str&gt;, …) <span class="hljs-comment"># `user=&lt;str&gt;, password=&lt;str&gt;, database=&lt;str&gt;`.</span>
1688+
&lt;cursor&gt; = db.cursor() <span class="hljs-comment"># Only cursor has execute method.</span>
16891689
&lt;cursor&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>) <span class="hljs-comment"># Can raise a subclass of connector.Error.</span>
16901690
&lt;cursor&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;list/tuple&gt;) <span class="hljs-comment"># Replaces '%s's in query with values.</span>
16911691
&lt;cursor&gt;.execute(<span class="hljs-string">'&lt;query&gt;'</span>, &lt;dict/namedtuple&gt;) <span class="hljs-comment"># Replaces '%(&lt;key&gt;)s's with values.</span>
@@ -1701,13 +1701,13 @@
17011701

17021702
<div><h3 id="encode-1">Encode</h3><pre><code class="python language-python hljs">&lt;bytes&gt; = bytes(&lt;coll_of_ints&gt;) <span class="hljs-comment"># Ints must be in range from 0 to 255.</span>
17031703
&lt;bytes&gt; = bytes(&lt;str&gt;, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Or: &lt;str&gt;.encode('utf-8')</span>
1704-
&lt;bytes&gt; = &lt;int&gt;.to_bytes(n_bytes, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span>
1704+
&lt;bytes&gt; = &lt;int&gt;.to_bytes(n_bytes, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`.</span>
17051705
&lt;bytes&gt; = bytes.fromhex(<span class="hljs-string">'&lt;hex&gt;'</span>) <span class="hljs-comment"># Hex numbers can be separated by spaces.</span>
17061706
</code></pre></div>
17071707

17081708
<div><h3 id="decode-1">Decode</h3><pre><code class="python language-python hljs">&lt;list&gt; = list(&lt;bytes&gt;) <span class="hljs-comment"># Returns ints in range from 0 to 255.</span>
17091709
&lt;str&gt; = str(&lt;bytes&gt;, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Or: &lt;bytes&gt;.decode('utf-8')</span>
1710-
&lt;int&gt; = int.from_bytes(&lt;bytes&gt;, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span>
1710+
&lt;int&gt; = int.from_bytes(&lt;bytes&gt;, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`.</span>
17111711
<span class="hljs-string">'&lt;hex&gt;'</span> = &lt;bytes&gt;.hex() <span class="hljs-comment"># Returns a string of hexadecimal numbers.</span>
17121712
</code></pre></div>
17131713

@@ -1786,7 +1786,7 @@
17861786

17871787
<pre><code class="python language-python hljs">&lt;list&gt; = list(&lt;mview&gt;) <span class="hljs-comment"># Returns list of ints or floats.</span>
17881788
&lt;str&gt; = str(&lt;mview&gt;, <span class="hljs-string">'utf-8'</span>) <span class="hljs-comment"># Treats mview as a bytes object.</span>
1789-
&lt;int&gt; = int.from_bytes(&lt;mview&gt;, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`</span>
1789+
&lt;int&gt; = int.from_bytes(&lt;mview&gt;, …) <span class="hljs-comment"># `byteorder='big/little', signed=False`.</span>
17901790
<span class="hljs-string">'&lt;hex&gt;'</span> = &lt;mview&gt;.hex() <span class="hljs-comment"># Treats mview as a bytes object.</span>
17911791
</code></pre>
17921792
<div><h2 id="deque"><a href="#deque" name="deque">#</a>Deque</h2><p><strong>A thread-safe list with efficient appends and pops from either side. Pronounced "deck".</strong></p><pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> collections <span class="hljs-keyword">import</span> deque

0 commit comments

Comments
 (0)