Skip to content

Commit 3cff942

Browse files
committed
SQLite, Bytes, Web
1 parent 80a9eae commit 3cff942

3 files changed

Lines changed: 45 additions & 44 deletions

File tree

README.md

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,15 +1884,15 @@ import sqlite3
18841884

18851885
### Read
18861886
```python
1887-
<cursor> = <conn>.execute('<query>') # Can raise a subclass of the sqlite3.Error.
1887+
<cursor> = <conn>.execute('<query>') # Can raise a subclass of the `sqlite3.Error`.
18881888
<tuple> = <cursor>.fetchone() # Returns the next row. Also next(<cursor>).
18891889
<list> = <cursor>.fetchall() # Returns remaining rows. Also list(<cursor>).
18901890
```
18911891

18921892
### Write
18931893
```python
1894-
<conn>.execute('<query>') # Can raise a subclass of the sqlite3.Error.
1895-
<conn>.commit() # Saves all changes since the last commit.
1894+
<conn>.execute('<query>') # Can raise a subclass of the `sqlite3.Error`.
1895+
<conn>.commit() # Saves all the changes since the last commit.
18961896
<conn>.rollback() # Discards all changes since the last commit.
18971897
```
18981898

@@ -1904,7 +1904,7 @@ with <conn>: # Exits the block with commit() o
19041904

19051905
### Placeholders
19061906
```python
1907-
<conn>.execute('<query>', <list/tuple>) # Replaces every question mark with an item.
1907+
<conn>.execute('<query>', <list/tuple>) # Replaces every question mark with its item.
19081908
<conn>.execute('<query>', <dict/namedtuple>) # Replaces every :<key> with a matching value.
19091909
<conn>.executemany('<query>', <coll_of_coll>) # Executes the query once for each collection.
19101910
```
@@ -1922,7 +1922,7 @@ with <conn>: # Exits the block with commit() o
19221922
```
19231923

19241924
### SQLAlchemy
1925-
**Library for interacting with various DB systems via SQL, method chaining, or ORM.**
1925+
**Library for interacting with various DB systems via SQL, [method chaining](https://docs.sqlalchemy.org/en/latest/tutorial/data_select.html#the-select-sql-expression-construct) or [ORM](https://docs.sqlalchemy.org/en/latest/orm/quickstart.html#simple-select).**
19261926
```python
19271927
# $ pip3 install sqlalchemy
19281928
from sqlalchemy import create_engine, text
@@ -1946,31 +1946,32 @@ with <conn>.begin(): ... # Exits the block with a commit o
19461946

19471947
Bytes
19481948
-----
1949-
**Immutable sequence of single bytes. Mutable version is called bytearray.**
1949+
**An immutable sequence of single bytes. Mutable version is called bytearray.**
19501950

19511951
```python
1952-
<bytes> = b'<str>' # Only accepts ASCII chars and [\x00-\xff].
1953-
<int> = <bytes>[index] # Returns an integer in range from 0 to 255.
1954-
<bytes> = <bytes>[<slice>] # Returns bytes even if it has one element.
1955-
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
1952+
<bytes> = b'<str>' # Accepts ASCII characters and \x00 to \xff.
1953+
<int> = <bytes>[index] # Returns the byte as int between 0 and 255.
1954+
<bytes> = <bytes>[<slice>] # Returns bytes even if it has one element.
1955+
<bytes> = <bytes>.join(<coll_of_bytes>) # Joins elements using bytes as a separator.
19561956
```
19571957

19581958
### Encode
19591959
```python
1960-
<bytes> = bytes(<coll_of_ints>) # Integers must be in range from 0 to 255.
1961-
<bytes> = bytes(<str>, 'utf-8') # Encodes the string. Also <str>.encode().
1962-
<bytes> = bytes.fromhex('<hex>') # Hex pairs can be separated by whitespace.
1963-
<bytes> = <int>.to_bytes(n_bytes, ) # `byteorder='big/little', signed=False`.
1960+
<bytes> = bytes(<coll_of_ints>) # Passed integers must be between 0 and 255.
1961+
<bytes> = bytes(<str>, 'utf-8') # Encodes the string. Same as <str>.encode().
1962+
<bytes> = bytes.fromhex('<hex>') # Hex pairs can be separated by whitespaces.
1963+
<bytes> = <int>.to_bytes(n_bytes, 'big') # Accepts `byteorder='little', signed=True`.
19641964
```
19651965

19661966
### Decode
19671967
```python
1968-
<list> = list(<bytes>) # Returns integers in range from 0 to 255.
1969-
<str> = str(<bytes>, 'utf-8') # Returns a string. Also <bytes>.decode().
1970-
<str> = <bytes>.hex() # Returns hex pairs. Accepts `sep=<str>`.
1971-
<int> = int.from_bytes(<bytes>, ) # `byteorder='big/little', signed=False`.
1968+
<list> = list(<bytes>) # Returns a list of ints between 0 and 255.
1969+
<str> = str(<bytes>, 'utf-8') # Returns a string. Same as <bytes>.decode().
1970+
<str> = <bytes>.hex() # Returns hex pairs separated by `sep=<str>`.
1971+
<int> = int.from_bytes(<bytes>, 'big') # Accepts `byteorder='little', signed=True`.
19721972
```
19731973

1974+
19741975
### Read Bytes from File
19751976
```python
19761977
def read_bytes(filename):
@@ -2142,7 +2143,7 @@ match <object/expression>:
21422143
<mapping_patt> = {<value_pattern>: <patt>, ...} # Matches a dict if it has matching items.
21432144
<class_pattern> = <type>(<attr_name>=<patt>, ...) # Matches object that has matching attrbs.
21442145
```
2145-
* **Sequence pattern can also be written as a tuple, either with or without the brackets.**
2146+
* **The sequence pattern can also be written as a tuple, either with or without the brackets.**
21462147
* **Use `'*<name>'` and `'**<name>'` in sequence/mapping patterns to bind remaining items.**
21472148
* **Sequence pattern must match all items of the collection, while mapping pattern does not.**
21482149
* **Patterns can be surrounded with brackets to override their precedence: `'|'` > `'as'` > `','`. For example, `'[1, 2]'` is matched by the `'case 1|2, 2|3 as x if x == 2:'` block.**
@@ -2562,7 +2563,7 @@ def serve_html(sport):
25622563
* **`'fl.render_template(filename, <kwargs>)'` renders a file located in 'templates' dir.**
25632564
* **`'fl.abort(<int>)'` returns error code and `'return fl.redirect(<url>)'` redirects.**
25642565
* **`'fl.request.args[<str>]'` returns parameter from query string (URL part right of '?').**
2565-
* **`'fl.session[<str>] = <obj>'` stores session data. It requires secret key to be set at the startup with `'app.secret_key = <str>'`.**
2566+
* **`'fl.session[<str>] = <obj>'` stores session data and `'fl.session.clear()'` clears it. A session cookie key needs to be set at the startup with `'app.secret_key = <str>'`.**
25662567

25672568
### Serving JSON
25682569
```python
@@ -2783,7 +2784,7 @@ from PIL import Image
27832784
```
27842785

27852786
### Modes
2786-
* **`'L'` - Lightness (greyscale image). Each pixel is an integer between 0 and 255.**
2787+
* **`'L'` - Lightness (greyscale image). Each pixel is stored as an int between 0 and 255.**
27872788
* **`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three integers.**
27882789
* **`'RGBA'` - RGB with alpha. Low alpha (i.e. fourth int) makes pixel more transparent.**
27892790
* **`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.**

0 commit comments

Comments
 (0)