* **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.**
* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.**
* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.**
* **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.**
### Modes
@ -1800,13 +1800,13 @@ SQLite
**Server-less database engine that stores each database into separate file.**
### Connect
**Opens a connection to the database file. Creates a new file if path doesn't exist.**
```python
import sqlite3
db = sqlite3.connect('<path>') # Also ':memory:'.
...
db.close()
```
* **New database will be created if path doesn't exist.**
### Read
**Returned values can be of type str, int, float, bytes or None.**
@ -1963,12 +1963,12 @@ Memory View
<mview> = memoryview(<bytes/bytearray/array>)
<num> = <mview>[<index>] # Returns an int or a float.
<mview> = <mview>[<slice>] # Mview with rearranged elements.
<mview> = <mview>.cast('<typecode>') # Casts a memoryview to a new format.
<mview> = <mview>.cast('<typecode>') # Casts memoryview to the new format.
<mview>.release() # Releases the object's memory buffer.
```
```python
<bin_file>.write(<mview>) # Writes mview to a binary file.
<bin_file>.write(<mview>) # Appends mview to the binary file.
<bytes> = bytes(<mview>) # Creates a new bytes object.
<bytes> = <bytes>.join(<coll_of_mviews>) # Joins mviews using bytes object as sep.
<list> = list(<mview>) # Returns list of ints or floats.
<div><h3id="strings">Strings</h3><p><strong><codeclass="python hljs"><spanclass="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><codeclass="python language-python hljs">{<spanclass="hljs-string">'abcde'</span>!r:<<spanclass="hljs-number">10</span>} <spanclass="hljs-comment"># "'abcde' "</span>
<div><h3id="strings">Strings</h3><p><strong><codeclass="python hljs"><spanclass="hljs-string">'!r'</span></code> calls object's repr() method, instead of str(), to get a string.</strong></p><pre><codeclass="python language-python hljs">{<spanclass="hljs-string">'abcde'</span>!r:<<spanclass="hljs-number">10</span>} <spanclass="hljs-comment"># "'abcde' "</span>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'encoding=None'</span></code> means default encoding is used, which is platform dependent. Best practice is to use <codeclass="python hljs"><spanclass="hljs-string">'encoding="utf-8"'</span></code> whenever possible.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=None'</span></code> means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.</strong></li>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'newline=""'</span></code> means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.</strong></li>
<div><h2id="sqlite"><ahref="#sqlite"name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3id="connect">Connect</h3><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> sqlite3
<div><h2id="sqlite"><ahref="#sqlite"name="sqlite">#</a>SQLite</h2><p><strong>Server-less database engine that stores each database into separate file.</strong></p><div><h3id="connect">Connect</h3><p><strong>Opens a connection to the database file. Creates a new file if path doesn't exist.</strong></p><pre><codeclass="python language-python hljs"><spanclass="hljs-keyword">import</span> sqlite3
db = sqlite3.connect(<spanclass="hljs-string">'<path>'</span>) <spanclass="hljs-comment"># Also ':memory:'.</span>
...
db.close()
@ -1613,9 +1613,7 @@ db.close()
<ul>
<li><strong>New database will be created if path doesn't exist.</strong></li>
</ul>
<div><h3id="read-1">Read</h3><p><strong>Returned values can be of type str, int, float, bytes or None.</strong></p><pre><codeclass="python language-python hljs"><cursor> = db.execute(<spanclass="hljs-string">'<query>'</span>) <spanclass="hljs-comment"># Can raise sqlite3.OperationalError.</span>
<tuple> = <cursor>.fetchone() <spanclass="hljs-comment"># Returns next row. Also next(<cursor>).</span>
</ul><div><h4id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul>
</ul></div><div><h4id="integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets">Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:</h4><ul>
<li><strong><codeclass="python hljs"><spanclass="hljs-string">'x'</span></code> - pad byte</strong></li>
<num> = <mview>[<index>] <spanclass="hljs-comment"># Returns an int or a float.</span>
<mview> = <mview>[<slice>] <spanclass="hljs-comment"># Mview with rearranged elements.</span>
<mview> = <mview>.cast(<spanclass="hljs-string">'<typecode>'</span>) <spanclass="hljs-comment"># Casts a memoryview to a new format.</span>
<mview> = <mview>.cast(<spanclass="hljs-string">'<typecode>'</span>) <spanclass="hljs-comment"># Casts memoryview to the new format.</span>
<mview>.release() <spanclass="hljs-comment"># Releases the object's memory buffer.</span>
</code></pre></div>
<pre><codeclass="python language-python hljs"><bin_file>.write(<mview>) <spanclass="hljs-comment"># Writes mview to a binary file.</span>
<pre><codeclass="python language-python hljs"><bin_file>.write(<mview>) <spanclass="hljs-comment"># Appends mview to the binary file.</span>
<bytes> = bytes(<mview>) <spanclass="hljs-comment"># Creates a new bytes object.</span>
<bytes> = <bytes>.join(<coll_of_mviews>) <spanclass="hljs-comment"># Joins mviews using bytes object as sep.</span>
<list> = list(<mview>) <spanclass="hljs-comment"># Returns list of ints or floats.</span>