diff --git a/README.md b/README.md index 82b4529..75f701c 100644 --- a/README.md +++ b/README.md @@ -2536,7 +2536,7 @@ app = Flask(__name__) app.run() ``` * **Starts the app on `'http://localhost:5000'`.** -* **You will need a WSGI server like [waitress](https://flask.palletsprojects.com/en/latest/deploying/waitress/) and a HTTP server such as [nginx](https://flask.palletsprojects.com/en/latest/deploying/nginx/) to run globally.** +* **A WSGI server like [Waitress](https://flask.palletsprojects.com/en/latest/deploying/waitress/) and a HTTP server such as [Nginx](https://flask.palletsprojects.com/en/latest/deploying/nginx/) are needed to run globally.** ### Static Request diff --git a/index.html b/index.html index 04b36dd..fcad74c 100644 --- a/index.html +++ b/index.html @@ -120,8 +120,8 @@ product_of_elems = functools.reduce(lambda out list_of_chars = list(<str>)
<list>.insert(<int>, <el>) # Inserts item at index and moves the rest to the right.
<el> = <list>.pop([<int>]) # Removes and returns item at index or from the end.
@@ -386,7 +386,7 @@ Point(x=1, y=2
- Options can be generated dynamically:
f'{<el>:{<str/int>}[…]}'
.
-- Adding
'!r'
before the colon converts object to string by calling its repr() method.
+- Adding
'!r'
before the colon converts object to string by calling its repr() method (p. 14).
Strings
{'abcde':10} # 'abcde '
{'abcde':10.3} # 'abc '
@@ -750,7 +750,7 @@ player = Player(point, direction) #
#Decorator
- A decorator takes a function, adds some functionality and returns it.
-- It can be any callable, but is usually implemented as a function that returns a closure.
+- It can be any callable, but is usually implemented as a function that returns a closure.
@decorator_name
def function_that_gets_passed_to_decorator():
...
@@ -894,9 +894,9 @@ Z = dataclasses.make_dataclass('Z', [
-Objects can be made sortable with 'order=True'
and immutable with 'frozen=True'
.
-For object to be hashable, all attributes must be hashable and 'frozen' must be True.
-Function field() is needed because '<attr_name>: list = []'
would make a list that is shared among all instances. Its 'default_factory' argument can be any callable.
+Objects can be made sortable with 'order=True'
and immutable with 'frozen=True'
.
+For object to be hashable, all attributes must be hashable and 'frozen' must be True.
+Function field() is needed because '<attr_name>: list = []'
would make a list that is shared among all instances. Its 'default_factory' argument can be any callable (p. 17).
For attributes of arbitrary type use 'typing.Any'
.
Inline:
from dataclasses import make_dataclass
@@ -998,10 +998,10 @@ Z = dataclasses.make_dataclass('Z', [1, 2, 3)
Python has many different iterator objects:
-- Sequence iterators returned by the iter() function, such as list_iterator and set_iterator.
-- Objects returned by the itertools module, such as count, repeat and cycle.
-- Generators returned by the generator functions and generator expressions.
-- File objects returned by the open() function, etc.
+- Sequence iterators returned by the iter() function, such as list_iterator and set_iterator (p. 3).
+- Objects returned by the itertools module, such as count, repeat and cycle (p. 3).
+- Generators returned by the generator functions (p. 4) and generator expressions (p. 11).
+- File objects returned by the open() function (p. 22), etc.
Callable
- All functions and classes have a call() method, hence are callable.
- When this cheatsheet uses
'<function>'
as an argument, it actually means '<callable>'
.
@@ -1452,7 +1452,7 @@ shutil.rmtree(<path>) # Deletes t
- Paths can be either strings, Paths or DirEntry objects.
-- Functions report OS related errors by raising either OSError or one of its subclasses.
+- Functions report OS related errors by raising OSError or one of its subclasses (p. 23).
Shell Commands
<pipe> = os.popen('<command>') # Executes command in sh/cmd. Returns its stdout pipe.
<str> = <pipe>.read(size=-1) # Reads 'size' chars or until EOF. Also readline/s().
@@ -1514,8 +1514,8 @@ CompletedProcess(args=['bc', 'newline=""'
argument, or newlines embedded inside quoted fields will not be interpreted correctly!
-
- To print the spreadsheet to the console use Tabulate library.
-- For XML and binary Excel files (xlsx, xlsm and xlsb) use Pandas library.
+- To print the spreadsheet to the console use Tabulate library (p. 34).
+- For XML and binary Excel files (xlsx, xlsm and xlsb) use Pandas library (p. 46).
- Reader accepts any iterator of strings, not just files.
Write
<writer> = csv.writer(<file>) # Also: `dialect='excel', delimiter=','`.
@@ -1588,7 +1588,7 @@ CompletedProcess(args=['bc', ISO formatted strings.
+- Bools will be stored and returned as ints and dates as ISO formatted strings (p. 9).
Example
Values are not actually saved in this example because 'conn.commit()'
is omitted!
>>> conn = sqlite3.connect('test.db')
>>> conn.execute('CREATE TABLE person (person_id INTEGER PRIMARY KEY, name, height)')
@@ -1761,7 +1761,7 @@ CompletedProcess(args=['bc', Thread Pool Executor
- Object that manages thread execution.
-- An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable.
+- An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable (p. 25).
<Exec> = ThreadPoolExecutor(max_workers=None) # Or: `with ThreadPoolExecutor() as <name>: …`
<Exec>.shutdown(wait=True) # Blocks until all threads finish executing.
@@ -1898,7 +1898,7 @@ ValueError: malformed node or string
- Coroutine definition starts with
'async'
and its call with 'await'
.
'asyncio.run(<coroutine>)'
is the main entry point for asynchronous programs.
- Functions wait(), gather() and as_completed() start multiple coroutines at the same time.
-- Asyncio module also provides its own Queue, Event, Lock and Semaphore classes.
+- Asyncio module also provides its own Queue, Event, Lock and Semaphore classes (p. 30).
Runs a terminal game where you control an asterisk that must avoid numbers:
import asyncio, collections, curses, curses.textpad, enum, random
P = collections.namedtuple('P', 'x y') # Position
@@ -2081,7 +2081,7 @@ app.run()
- Starts the app on
'http://localhost:5000'
.
-- You will need a WSGI server like waitress and a HTTP server such as nginx to run globally.
+- A WSGI server like Waitress and a HTTP server such as Nginx are needed to run globally.
Static Request
@app.route('/img/<path:filename>')
def serve_file(filename):
@@ -2162,7 +2162,7 @@ drawer = cg.output.GraphvizOutput(output_file=filename)
-- The "latest and greatest" profiler that can also monitor GPU usage is called Scalene.
+- The "latest and greatest" profiler that can also monitor GPU usage is called Scalene.
#NumPy
Array manipulation mini-language. It can run up to one hundred times faster than the equivalent Python code. An even faster alternative that runs on a GPU is called CuPy.
# $ pip3 install numpy
import numpy as np
diff --git a/pdf/remove_links.py b/pdf/remove_links.py
index 7deea6c..6edf503 100755
--- a/pdf/remove_links.py
+++ b/pdf/remove_links.py
@@ -24,6 +24,7 @@ MATCHES = {
'Bools will be stored and returned as ints and dates as ISO formatted strings.': 'Bools will be stored and returned as ints and dates as ISO formatted strings (p. 9).',
'An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable.': 'An object with the same interface called ProcessPoolExecutor provides true parallelism by running a separate interpreter in each process. All arguments must be pickable (p. 25).',
'Asyncio module also provides its own Queue, Event, Lock and Semaphore classes.': 'Asyncio module also provides its own Queue, Event, Lock and Semaphore classes (p. 30).',
+ 'A WSGI server like Waitress and a HTTP server such as Nginx are needed to run globally.': 'A WSGI server like Waitress and a HTTP server such as Nginx are needed to run globally.',
'The "latest and greatest" profiler that can also monitor GPU usage is called Scalene.': 'The "latest and greatest" profiler that can also monitor GPU usage is called Scalene.',
}