From b393c21c7b35accec1b7321aca67896f4be96562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 4 Sep 2022 20:26:28 +0200 Subject: [PATCH 001/554] Itertools, Numbers, Combinatorics, OS Commands --- README.md | 138 +++++++++++++++++++++++++-------------------------- index.html | 142 ++++++++++++++++++++++++++--------------------------- parse.js | 8 +-- 3 files changed, 144 insertions(+), 144 deletions(-) diff --git a/README.md b/README.md index de65e87f0..8327a799d 100644 --- a/README.md +++ b/README.md @@ -200,23 +200,23 @@ Iterator ### Itertools ```python -from itertools import count, repeat, cycle, chain, islice +import itertools as it ``` ```python - = count(start=0, step=1) # Returns updated value endlessly. Accepts floats. - = repeat( [, times]) # Returns element endlessly or 'times' times. - = cycle() # Repeats the sequence endlessly. + = it.count(start=0, step=1) # Returns updated value endlessly. Accepts floats. + = it.repeat( [, times]) # Returns element endlessly or 'times' times. + = it.cycle() # Repeats the sequence endlessly. ``` ```python - = chain(, [, ...]) # Empties collections in order (figuratively). - = chain.from_iterable() # Empties collections inside a collection in order. + = it.chain(, [, ...]) # Empties collections in order (figuratively). + = it.chain.from_iterable() # Empties collections inside a collection in order. ``` ```python - = islice(, to_exclusive) # Only returns first 'to_exclusive' elements. - = islice(, from_inclusive, …) # `to_exclusive, +step_size`. Indices can be None. + = it.islice(, to_exclusive) # Only returns first 'to_exclusive' elements. + = it.islice(, from_inc, …) # `to_exclusive, +step_size`. Indices can be None. ``` @@ -486,11 +486,11 @@ Format Numbers ------- ```python - = int() # Or: math.floor() - = float() # Or: - = complex(real=0, imag=0) # Or: ± j - = fractions.Fraction(0, 1) # Or: Fraction(numerator=0, denominator=1) - = decimal.Decimal() # Or: Decimal((sign, digits, exponent)) + = int() # Or: math.floor() + = float() # Or: + = complex(real=0, imag=0) # Or: ± j + = fractions.Fraction(0, 1) # Or: Fraction(numerator=0, denominator=1) + = decimal.Decimal() # Or: Decimal((sign, digits, exponent)) ``` * **`'int()'` and `'float()'` raise ValueError on malformed strings.** * **Decimal numbers are stored exactly, unlike most floats where `'1.1 + 2.2 != 3.3'`.** @@ -499,47 +499,46 @@ Numbers ### Basic Functions ```python - = pow(, ) # Or: ** - = abs() # = abs() - = round( [, ±ndigits]) # `round(126, -1) == 130` + = pow(, ) # Or: ** + = abs() # = abs() + = round( [, ±ndigits]) # `round(126, -1) == 130` ``` ### Math ```python -from math import e, pi, inf, nan, isinf, isnan -from math import sin, cos, tan, asin, acos, atan, degrees, radians -from math import log, log10, log2 +from math import e, pi, inf, nan, isinf, isnan # ` == nan` is always False. +from math import sin, cos, tan, asin, acos, atan # Also: degrees, radians. +from math import log, log10, log2 # Log can accept base as second arg. ``` ### Statistics ```python -from statistics import mean, median, variance, stdev, quantiles, groupby +from statistics import mean, median, variance # Also: stdev, quantiles, groupby. ``` ### Random ```python -from random import random, randint, choice, shuffle, gauss, seed - - = random() # A float inside [0, 1). - = randint(from_inc, to_inc) # An int inside [from_inc, to_inc]. - = choice() # Keeps the sequence intact. +from random import random, randint, choice # Also shuffle, gauss, triangular, seed. + = random() # A float inside [0, 1). + = randint(from_inc, to_inc) # An int inside [from_inc, to_inc]. + = choice() # Keeps the sequence intact. ``` ### Bin, Hex ```python - = ±0b # Or: ±0x - = int('±', 2) # Or: int('±', 16) - = int('±0b', 0) # Or: int('±0x', 0) - = bin() # Returns '[-]0b'. + = ±0b # Or: ±0x + = int('±', 2) # Or: int('±', 16) + = int('±0b', 0) # Or: int('±0x', 0) + = bin() # Returns '[-]0b'. ``` ### Bitwise Operators ```python - = & # And (0b1100 & 0b1010 == 0b1000). - = | # Or (0b1100 | 0b1010 == 0b1110). - = ^ # Xor (0b1100 ^ 0b1010 == 0b0110). - = << n_bits # Left shift. Use >> for right. - = ~ # Not. Also - - 1. + = & # And (0b1100 & 0b1010 == 0b1000). + = | # Or (0b1100 | 0b1010 == 0b1110). + = ^ # Xor (0b1100 ^ 0b1010 == 0b0110). + = << n_bits # Left shift. Use >> for right. + = ~ # Not. Also - - 1. ``` @@ -549,39 +548,40 @@ Combinatorics * **If you want to print the iterator, you need to pass it to the list() function first!** ```python -from itertools import product, combinations, combinations_with_replacement, permutations +import itertools as it ``` ```python ->>> product([0, 1], repeat=3) -[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), ..., (1, 1, 1)] +>>> it.product([0, 1], repeat=3) +[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), + (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)] ``` ```python ->>> product('abc', 'abc') # a b c -[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x - ('b', 'a'), ('b', 'b'), ('b', 'c'), # b x x x - ('c', 'a'), ('c', 'b'), ('c', 'c')] # c x x x +>>> it.product('abc', 'abc') # a b c +[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x + ('b', 'a'), ('b', 'b'), ('b', 'c'), # b x x x + ('c', 'a'), ('c', 'b'), ('c', 'c')] # c x x x ``` ```python ->>> combinations('abc', 2) # a b c -[('a', 'b'), ('a', 'c'), # a . x x - ('b', 'c')] # b . . x +>>> it.combinations('abc', 2) # a b c +[('a', 'b'), ('a', 'c'), # a . x x + ('b', 'c')] # b . . x ``` ```python ->>> combinations_with_replacement('abc', 2) # a b c -[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x - ('b', 'b'), ('b', 'c'), # b . x x - ('c', 'c')] # c . . x +>>> it.combinations_with_replacement('abc', 2) # a b c +[('a', 'a'), ('a', 'b'), ('a', 'c'), # a x x x + ('b', 'b'), ('b', 'c'), # b . x x + ('c', 'c')] # c . . x ``` ```python ->>> permutations('abc', 2) # a b c -[('a', 'b'), ('a', 'c'), # a . x x - ('b', 'a'), ('b', 'c'), # b x . x - ('c', 'a'), ('c', 'b')] # c x x . +>>> it.permutations('abc', 2) # a b c +[('a', 'b'), ('a', 'c'), # a . x x + ('b', 'a'), ('b', 'c'), # b x . x + ('c', 'a'), ('c', 'b')] # c x x . ``` @@ -1701,34 +1701,34 @@ import os, shutil, subprocess ``` ```python -os.chdir() # Changes the current working directory. -os.mkdir(, mode=0o777) # Creates a directory. Mode is in octal. -os.makedirs(, mode=0o777) # Creates all path's dirs. Also: `exist_ok=False`. +os.chdir() # Changes the current working directory. +os.mkdir(, mode=0o777) # Creates a directory. Permissions are in octal. +os.makedirs(, mode=0o777) # Creates all path's dirs. Also: `exist_ok=False`. ``` ```python -shutil.copy(from, to) # Copies the file. 'to' can exist or be a dir. -shutil.copytree(from, to) # Copies the directory. 'to' must not exist. +shutil.copy(from, to) # Copies the file. 'to' can exist or be a dir. +shutil.copytree(from, to) # Copies the directory. 'to' must not exist. ``` ```python -os.rename(from, to) # Renames/moves the file or directory. -os.replace(from, to) # Same, but overwrites 'to' if it exists. +os.rename(from, to) # Renames/moves the file or directory. +os.replace(from, to) # Same, but overwrites 'to' if it exists. ``` ```python -os.remove() # Deletes the file. -os.rmdir() # Deletes the empty directory. -shutil.rmtree() # Deletes the directory. +os.remove() # Deletes the file. +os.rmdir() # Deletes the empty directory. +shutil.rmtree() # Deletes the directory. ``` * **Paths can be either strings, Paths or DirEntry objects.** * **Functions report OS related errors by raising either OSError or one of its [subclasses](#exceptions-1).** ### Shell Commands ```python - = os.popen('') # Executes command in sh/cmd and returns its stdout pipe. - = .read(size=-1) # Reads 'size' chars or until EOF. Also readline/s(). - = .close() # Closes the pipe. Returns None on success, int on error. + = os.popen('') # Executes command in sh/cmd. Returns its stdout pipe. + = .read(size=-1) # Reads 'size' chars or until EOF. Also readline/s(). + = .close() # Closes the pipe. Returns None on success. ``` #### Sends '1 + 1' to the basic calculator and captures its output: @@ -1754,8 +1754,8 @@ JSON ```python import json - = json.dumps() # Converts object to JSON string. - = json.loads() # Converts JSON string to object. + = json.dumps() # Converts object to JSON string. + = json.loads() # Converts JSON string to object. ``` ### Read Object from JSON File @@ -1779,8 +1779,8 @@ Pickle ```python import pickle - = pickle.dumps() # Converts object to bytes object. - = pickle.loads() # Converts bytes object to object. + = pickle.dumps() # Converts object to bytes object. + = pickle.loads() # Converts bytes object to object. ``` ### Read Object from File diff --git a/index.html b/index.html index f82571f44..16b96657a 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -220,18 +220,18 @@ <list> = list(<iter>) # Returns a list of iterator's remaining elements. -

Itertools

from itertools import count, repeat, cycle, chain, islice
+

Itertools

import itertools as it
 
-
<iter> = count(start=0, step=1)             # Returns updated value endlessly. Accepts floats.
-<iter> = repeat(<el> [, times])             # Returns element endlessly or 'times' times.
-<iter> = cycle(<collection>)                # Repeats the sequence endlessly.
+
<iter> = it.count(start=0, step=1)          # Returns updated value endlessly. Accepts floats.
+<iter> = it.repeat(<el> [, times])          # Returns element endlessly or 'times' times.
+<iter> = it.cycle(<collection>)             # Repeats the sequence endlessly.
 
-
<iter> = chain(<coll_1>, <coll_2> [, ...])  # Empties collections in order (figuratively).
-<iter> = chain.from_iterable(<coll>)        # Empties collections inside a collection in order.
+
<iter> = it.chain(<coll>, <coll> [, ...])   # Empties collections in order (figuratively).
+<iter> = it.chain.from_iterable(<coll>)     # Empties collections inside a collection in order.
 
-
<iter> = islice(<coll>, to_exclusive)       # Only returns first 'to_exclusive' elements.
-<iter> = islice(<coll>, from_inclusive, …)  # `to_exclusive, +step_size`. Indices can be None.
+
<iter> = it.islice(<coll>, to_exclusive)    # Only returns first 'to_exclusive' elements.
+<iter> = it.islice(<coll>, from_inc, …)     # `to_exclusive, +step_size`. Indices can be None.
 

#Generator

  • Any function that contains a yield statement returns a generator.
  • @@ -444,11 +444,11 @@ {90:X} # '5A'
-

#Numbers

<int>      = int(<float/str/bool>)       # Or: math.floor(<float>)
-<float>    = float(<int/str/bool>)       # Or: <real>e±<int>
-<complex>  = complex(real=0, imag=0)     # Or: <real> ± <real>j
-<Fraction> = fractions.Fraction(0, 1)    # Or: Fraction(numerator=0, denominator=1)
-<Decimal>  = decimal.Decimal(<str/int>)  # Or: Decimal((sign, digits, exponent))
+

#Numbers

<int>      = int(<float/str/bool>)                # Or: math.floor(<float>)
+<float>    = float(<int/str/bool>)                # Or: <real>e±<int>
+<complex>  = complex(real=0, imag=0)              # Or: <real> ± <real>j
+<Fraction> = fractions.Fraction(0, 1)             # Or: Fraction(numerator=0, denominator=1)
+<Decimal>  = decimal.Decimal(<str/int>)           # Or: Decimal((sign, digits, exponent))
 
    @@ -457,67 +457,67 @@
  • Floats can be compared with: 'math.isclose(<float>, <float>)'.
  • Precision of decimal operations is set with: 'decimal.getcontext().prec = <int>'.
-

Basic Functions

<num> = pow(<num>, <num>)                # Or: <num> ** <num>
-<num> = abs(<num>)                       # <float> = abs(<complex>)
-<num> = round(<num> [, ±ndigits])        # `round(126, -1) == 130`
+

Basic Functions

<num> = pow(<num>, <num>)                         # Or: <num> ** <num>
+<num> = abs(<num>)                                # <float> = abs(<complex>)
+<num> = round(<num> [, ±ndigits])                 # `round(126, -1) == 130`
 
-

Math

from math import e, pi, inf, nan, isinf, isnan
-from math import sin, cos, tan, asin, acos, atan, degrees, radians
-from math import log, log10, log2
+

Math

from math import e, pi, inf, nan, isinf, isnan    # `<el> == nan` is always False.
+from math import sin, cos, tan, asin, acos, atan  # Also: degrees, radians.
+from math import log, log10, log2                 # Log can accept base as second arg.
 
-

Statistics

from statistics import mean, median, variance, stdev, quantiles, groupby
+

Statistics

from statistics import mean, median, variance     # Also: stdev, quantiles, groupby.
 
-

Random

from random import random, randint, choice, shuffle, gauss, seed
-
-<float> = random()                       # A float inside [0, 1).
-<int>   = randint(from_inc, to_inc)      # An int inside [from_inc, to_inc].
-<el>    = choice(<sequence>)             # Keeps the sequence intact.
+

Random

from random import random, randint, choice        # Also shuffle, gauss, triangular, seed.
+<float> = random()                                # A float inside [0, 1).
+<int>   = randint(from_inc, to_inc)               # An int inside [from_inc, to_inc].
+<el>    = choice(<sequence>)                      # Keeps the sequence intact.
 
-

Bin, Hex

<int> = ±0b<bin>                         # Or: ±0x<hex>
-<int> = int('±<bin>', 2)                 # Or: int('±<hex>', 16)
-<int> = int('±0b<bin>', 0)               # Or: int('±0x<hex>', 0)
-<str> = bin(<int>)                       # Returns '[-]0b<bin>'.
+

Bin, Hex

<int> = ±0b<bin>                                  # Or: ±0x<hex>
+<int> = int('±<bin>', 2)                          # Or: int('±<hex>', 16)
+<int> = int('±0b<bin>', 0)                        # Or: int('±0x<hex>', 0)
+<str> = bin(<int>)                                # Returns '[-]0b<bin>'.
 
-

Bitwise Operators

<int> = <int> & <int>                    # And (0b1100 & 0b1010 == 0b1000).
-<int> = <int> | <int>                    # Or  (0b1100 | 0b1010 == 0b1110).
-<int> = <int> ^ <int>                    # Xor (0b1100 ^ 0b1010 == 0b0110).
-<int> = <int> << n_bits                  # Left shift. Use >> for right.
-<int> = ~<int>                           # Not. Also -<int> - 1.
+

Bitwise Operators

<int> = <int> & <int>                             # And (0b1100 & 0b1010 == 0b1000).
+<int> = <int> | <int>                             # Or  (0b1100 | 0b1010 == 0b1110).
+<int> = <int> ^ <int>                             # Xor (0b1100 ^ 0b1010 == 0b0110).
+<int> = <int> << n_bits                           # Left shift. Use >> for right.
+<int> = ~<int>                                    # Not. Also -<int> - 1.
 

#Combinatorics

  • Every function returns an iterator.
  • If you want to print the iterator, you need to pass it to the list() function first!
  • -
from itertools import product, combinations, combinations_with_replacement, permutations
+
import itertools as it
 
-
>>> product([0, 1], repeat=3)
-[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1), ..., (1, 1, 1)]
+
>>> it.product([0, 1], repeat=3)
+[(0, 0, 0), (0, 0, 1), (0, 1, 0), (0, 1, 1),
+ (1, 0, 0), (1, 0, 1), (1, 1, 0), (1, 1, 1)]
 
-
>>> product('abc', 'abc')                    #   a  b  c
-[('a', 'a'), ('a', 'b'), ('a', 'c'),         # a x  x  x
- ('b', 'a'), ('b', 'b'), ('b', 'c'),         # b x  x  x
- ('c', 'a'), ('c', 'b'), ('c', 'c')]         # c x  x  x
+
>>> it.product('abc', 'abc')                      #   a  b  c
+[('a', 'a'), ('a', 'b'), ('a', 'c'),              # a x  x  x
+ ('b', 'a'), ('b', 'b'), ('b', 'c'),              # b x  x  x
+ ('c', 'a'), ('c', 'b'), ('c', 'c')]              # c x  x  x
 
-
>>> combinations('abc', 2)                   #   a  b  c
-[('a', 'b'), ('a', 'c'),                     # a .  x  x
- ('b', 'c')]                                 # b .  .  x
+
>>> it.combinations('abc', 2)                     #   a  b  c
+[('a', 'b'), ('a', 'c'),                          # a .  x  x
+ ('b', 'c')]                                      # b .  .  x
 
-
>>> combinations_with_replacement('abc', 2)  #   a  b  c
-[('a', 'a'), ('a', 'b'), ('a', 'c'),         # a x  x  x
- ('b', 'b'), ('b', 'c'),                     # b .  x  x
- ('c', 'c')]                                 # c .  .  x
+
>>> it.combinations_with_replacement('abc', 2)    #   a  b  c
+[('a', 'a'), ('a', 'b'), ('a', 'c'),              # a x  x  x
+ ('b', 'b'), ('b', 'c'),                          # b .  x  x
+ ('c', 'c')]                                      # c .  .  x
 
-
>>> permutations('abc', 2)                   #   a  b  c
-[('a', 'b'), ('a', 'c'),                     # a .  x  x
- ('b', 'a'), ('b', 'c'),                     # b x  .  x
- ('c', 'a'), ('c', 'b')]                     # c x  x  .
+
>>> it.permutations('abc', 2)                     #   a  b  c
+[('a', 'b'), ('a', 'c'),                          # a .  x  x
+ ('b', 'a'), ('b', 'c'),                          # b x  .  x
+ ('c', 'a'), ('c', 'b')]                          # c x  x  .
 

#Datetime

  • Module 'datetime' provides 'date' <D>, 'time' <T>, 'datetime' <DT> and 'timedelta' <TD> classes. All are immutable and hashable.
  • @@ -1434,27 +1434,27 @@

    #OS Commands

    import os, shutil, subprocess
     
    -
    os.chdir(<path>)                 # Changes the current working directory.
    -os.mkdir(<path>, mode=0o777)     # Creates a directory. Mode is in octal.
    -os.makedirs(<path>, mode=0o777)  # Creates all path's dirs. Also: `exist_ok=False`.
    +
    os.chdir(<path>)                    # Changes the current working directory.
    +os.mkdir(<path>, mode=0o777)        # Creates a directory. Permissions are in octal.
    +os.makedirs(<path>, mode=0o777)     # Creates all path's dirs. Also: `exist_ok=False`.
     
    -
    shutil.copy(from, to)            # Copies the file. 'to' can exist or be a dir.
    -shutil.copytree(from, to)        # Copies the directory. 'to' must not exist.
    +
    shutil.copy(from, to)               # Copies the file. 'to' can exist or be a dir.
    +shutil.copytree(from, to)           # Copies the directory. 'to' must not exist.
     
    -
    os.rename(from, to)              # Renames/moves the file or directory.
    -os.replace(from, to)             # Same, but overwrites 'to' if it exists.
    +
    os.rename(from, to)                 # Renames/moves the file or directory.
    +os.replace(from, to)                # Same, but overwrites 'to' if it exists.
     
    -
    os.remove(<path>)                # Deletes the file.
    -os.rmdir(<path>)                 # Deletes the empty directory.
    -shutil.rmtree(<path>)            # Deletes the directory.
    +
    os.remove(<path>)                   # Deletes the file.
    +os.rmdir(<path>)                    # Deletes the empty directory.
    +shutil.rmtree(<path>)               # Deletes the directory.
     
    • Paths can be either strings, Paths or DirEntry objects.
    • Functions report OS related errors by raising either OSError or one of its subclasses.
    -

    Shell Commands

    <pipe> = os.popen('<command>')   # Executes command in sh/cmd and returns its stdout pipe.
    -<str>  = <pipe>.read(size=-1)    # Reads 'size' chars or until EOF. Also readline/s().
    -<int>  = <pipe>.close()          # Closes the pipe. Returns None on success, int on error.
    +

    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().
    +<int>  = <pipe>.close()             # Closes the pipe. Returns None on success.
     

    Sends '1 + 1' to the basic calculator and captures its output:

    >>> subprocess.run('bc', input='1 + 1\n', capture_output=True, text=True)
    @@ -1470,8 +1470,8 @@
     

    #JSON

    Text file format for storing collections of strings and numbers.

    import json
    -<str>    = json.dumps(<object>)    # Converts object to JSON string.
    -<object> = json.loads(<str>)       # Converts JSON string to object.
    +<str>    = json.dumps(<object>)     # Converts object to JSON string.
    +<object> = json.loads(<str>)        # Converts JSON string to object.
     
    @@ -1486,8 +1486,8 @@

    #Pickle

    Binary file format for storing Python objects.

    import pickle
    -<bytes>  = pickle.dumps(<object>)  # Converts object to bytes object.
    -<object> = pickle.loads(<bytes>)   # Converts bytes object to object.
    +<bytes>  = pickle.dumps(<object>)   # Converts object to bytes object.
    +<object> = pickle.loads(<bytes>)    # Converts bytes object to object.
     
    @@ -2906,7 +2906,7 @@

    Format

Runs a terminal game where you control an asterisk that must avoid numbers:

import asyncio, collections, curses, curses.textpad, enum, random
 
@@ -1903,11 +1903,12 @@ 

Format

# Starts running asyncio code. async def main_coroutine(screen): - state = {'*': P(0, 0), **{id_: P(W//2, H//2) for id_ in range(10)}} moves = asyncio.Queue() - coros = (*(random_controller(id_, moves) for id_ in range(10)), - human_controller(screen, moves), model(moves, state), view(state, screen)) - await asyncio.wait(coros, return_when=asyncio.FIRST_COMPLETED) + state = {'*': P(0, 0), **{id_: P(W//2, H//2) for id_ in range(10)}} + ai = [random_controller(id_, moves) for id_ in range(10)] + mvc = [human_controller(screen, moves), model(moves, state), view(state, screen)] + tasks = [asyncio.create_task(cor) for cor in ai + mvc] + await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED) async def random_controller(id_, moves): while True: @@ -2905,7 +2906,7 @@

Format

-

#SQLite

A server-less database engine that stores each database into a separate file.

Connect

Opens a connection to the database file. Creates a new file if path doesn't exist.

import sqlite3
-<conn> = sqlite3.connect(<path>)                # Also ':memory:'.
+

#SQLite

A server-less database engine that stores each database into a separate file.

import sqlite3
+<conn> = sqlite3.connect(<path>)                # Opens existing or new file. Also ':memory:'.
 <conn>.close()                                  # Closes the connection.
-
- - +
-

Read

Returned values can be of type str, int, float, bytes or None.

<cursor> = <conn>.execute('<query>')            # Can raise a subclass of sqlite3.Error.
+

Read

<cursor> = <conn>.execute('<query>')            # Can raise a subclass of sqlite3.Error.
 <tuple>  = <cursor>.fetchone()                  # Returns next row. Also next(<cursor>).
 <list>   = <cursor>.fetchall()                  # Returns remaining rows. Also list(<cursor>).
 
-

Write

<conn>.execute('<query>')                       # Can raise a subclass of sqlite3.Error.
 <conn>.commit()                                 # Saves all changes since the last commit.
 <conn>.rollback()                               # Discards all changes since the last commit.
@@ -1580,15 +1577,15 @@
     <conn>.execute('<query>')                   # depending on whether any exception occurred.
 
-

Placeholders

    -
  • Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.
  • -
  • Bools will be stored and returned as ints and dates as ISO formatted strings.
  • -
<conn>.execute('<query>', <list/tuple>)         # Replaces '?'s in query with values.
+

Placeholders

<conn>.execute('<query>', <list/tuple>)         # Replaces '?'s in query with values.
 <conn>.execute('<query>', <dict/namedtuple>)    # Replaces ':<key>'s with values.
 <conn>.executemany('<query>', <coll_of_above>)  # Runs execute() multiple times.
 
- +
    +
  • Passed values can be of type str, int, float, bytes, None, bool, datetime.date or datetime.datetime.
  • +
  • Bools will be stored and returned as ints and dates as ISO formatted strings.
  • +

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)')
 >>> conn.execute('INSERT INTO person VALUES (NULL, ?, ?)', ('Jean-Luc', 187)).lastrowid
@@ -2906,7 +2903,7 @@ 

Format

-

MySQL

Has a very similar interface, with differences listed below.

# $ pip3 install mysql-connector
-from mysql import connector
-<conn>   = connector.connect(host=<str>, …)     # `user=<str>, password=<str>, database=<str>`.
-<cursor> = <conn>.cursor()                      # Only cursor has execute() method.
-<cursor>.execute('<query>')                     # Can raise a subclass of connector.Error.
-<cursor>.execute('<query>', <list/tuple>)       # Replaces '%s's in query with values.
-<cursor>.execute('<query>', <dict/namedtuple>)  # Replaces '%(<key>)s's with values.
+

SqlAlchemy

# $ pip3 install sqlalchemy
+from sqlalchemy import create_engine, text
+<engine> = create_engine('<url>').connect()     # Url: 'dialect://user:password@host/dbname'.
+<conn>   = <engine>.connect()                   # Creates a connection. Also <conn>.close().
+<cursor> = <conn>.execute(text('<query>'), …)   # Replaces ':<key>'s with keyword arguments.
+with <conn>.begin(): ...                        # Exits the block with commit or rollback.
 
- +
┏━━━━━━━━━━━━┯━━━━━━━━━━━━━━┯━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
+┃ Dialects   │ pip3 install │ import    │ Dependencies                      ┃
+┠────────────┼──────────────┼───────────┼───────────────────────────────────┨
+┃ mysql      │ mysqlclient  │ MySQLdb   │ www.pypi.org/project/mysqlclient  ┃
+┃ postgresql │ psycopg2     │ psycopg2  │ www.psycopg.org/docs/install.html ┃
+┃ mssql      │ pyodbc       │ pyodbc    │ apt install g++ unixodbc-dev      ┃
+┃ oracle     │ cx_oracle    │ cx_Oracle │ Oracle Instant Client             ┃
+┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
+

#Bytes

Bytes object is an immutable sequence of single bytes. Mutable version is called bytearray.

<bytes> = b'<str>'                          # Only accepts ASCII characters and \x00-\xff.
 <int>   = <bytes>[<index>]                  # Returns an int in range from 0 to 255.
 <bytes> = <bytes>[<slice>]                  # Returns bytes even if it has only one element.
@@ -2903,7 +2910,7 @@ 

Format

M

math module, 7
memoryviews, 29
metaclass attribute, 32
-metaprogramming, 31-32
-mysql library, 27

+metaprogramming, 31-32

N

namedtuples, 3
nonlocal keyword, 12
diff --git a/pdf/index_for_pdf_print.html b/pdf/index_for_pdf_print.html index f9964fe03..269e72337 100644 --- a/pdf/index_for_pdf_print.html +++ b/pdf/index_for_pdf_print.html @@ -86,8 +86,7 @@

M

math module, 7
memoryviews, 29
metaclass attribute, 32
-metaprograming, 31-32
-mysql library, 27

+metaprograming, 31-32

N

namedtuples, 3
nonlocal keyword, 12
diff --git a/web/empty_script.py b/web/empty_script.py index 5e7920202..ec3e1caa8 100644 --- a/web/empty_script.py +++ b/web/empty_script.py @@ -21336,4 +21336,1062 @@ ### ## # +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# +# +## +### +#### +####### +########## +############# +################## +###################### +########################### +################################ +####################################### +############################################ +################################################# +###################################################### +########################################################### +############################################################### +################################################################### +###################################################################### +######################################################################### +########################################################################### +############################################################################ +############################################################################# +############################################################################# +############################################################################ +########################################################################### +######################################################################### +###################################################################### +################################################################### +############################################################### +########################################################### +###################################################### +################################################# +############################################ +####################################### +################################## +############################# +######################## +################### +############### +########### +######## +##### +### +## +# From 770d1fa4871e92b2d523f7b1919b7b5982619d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 16 Dec 2022 21:39:10 +0100 Subject: [PATCH 007/554] Regex, Inline, Enum, Operator, Mario --- README.md | 27 +++++++++++++-------------- index.html | 49 +++++++++++++++++++++++-------------------------- parse.js | 20 ++++++++++---------- 3 files changed, 46 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 809e20c51..77d7b80fc 100644 --- a/README.md +++ b/README.md @@ -363,7 +363,7 @@ import re * **Search() and match() return None if they can't find a match.** * **Argument `'flags=re.IGNORECASE'` can be used with all functions.** * **Argument `'flags=re.MULTILINE'` makes `'^'` and `'$'` match the start/end of each line.** -* **Argument `'flags=re.DOTALL'` makes dot also accept the `'\n'`.** +* **Argument `'flags=re.DOTALL'` makes `'.'` also accept the `'\n'`.** * **Use `r'\1'` or `'\\1'` for backreference (`'\1'` returns a character with octal code 1).** * **Add `'?'` after `'*'` and `'+'` to make them non-greedy.** @@ -787,7 +787,7 @@ Inline ``` ```python ->>> [a if a else 'zero' for a in (0, 1, 2, 3)] +>>> [a if a else 'zero' for a in (0, 1, 2, 3)] # `any([0, '', [], None]) == False` ['zero', 1, 2, 3] ``` @@ -800,8 +800,8 @@ point = Point(0, 0) # Returns its instance. ```python from enum import Enum -Direction = Enum('Direction', 'n e s w') # Creates an enum. -direction = Direction.n # Returns its member. +Direction = Enum('Direction', 'N E S W') # Creates an enum. +direction = Direction.N # Returns its member. ``` ```python @@ -1354,9 +1354,9 @@ def get_next_member(member): ### Inline ```python -Cutlery = Enum('Cutlery', 'fork knife spoon') -Cutlery = Enum('Cutlery', ['fork', 'knife', 'spoon']) -Cutlery = Enum('Cutlery', {'fork': 1, 'knife': 2, 'spoon': 3}) +Cutlery = Enum('Cutlery', 'FORK KNIFE SPOON') +Cutlery = Enum('Cutlery', ['FORK', 'KNIFE', 'SPOON']) +Cutlery = Enum('Cutlery', {'FORK': 1, 'KNIFE': 2, 'SPOON': 3}) ``` #### User-defined functions cannot be values, so they must be wrapped: @@ -1365,7 +1365,6 @@ from functools import partial LogicOp = Enum('LogicOp', {'AND': partial(lambda l, r: l and r), 'OR': partial(lambda l, r: l or r)}) ``` -* **Member names are in all caps because trying to access a member that is named after a reserved keyword raises SyntaxError.** Exceptions @@ -2156,10 +2155,10 @@ Operator **Module of functions that provide the functionality of operators.** ```python import operator as op - = op.add/sub/mul/truediv/floordiv/mod(, ) # +, -, *, /, //, % - = op.and_/or_/xor(, ) # &, |, ^ - = op.eq/ne/lt/le/gt/ge(, ) # ==, !=, <, <=, >, >= - = op.itemgetter/attrgetter/methodcaller() # [index/key], .name, .name() + = op.add/sub/mul/truediv/floordiv/mod(, ) # +, -, *, /, //, % + = op.and_/or_/xor(, ) # &, |, ^ + = op.eq/ne/lt/le/gt/ge(, ) # ==, !=, <, <=, >, >= + = op.itemgetter/attrgetter/methodcaller( [, ...]) # [index/key], .name, .name() ``` ```python @@ -3071,7 +3070,7 @@ def run(screen, images, mario, tiles): def update_speed(mario, tiles, pressed): x, y = mario.spd x += 2 * ((D.e in pressed) - (D.w in pressed)) - x -= (x > 0) - (x < 0) + x += (x < 0) - (x > 0) y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10 mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) @@ -3080,7 +3079,7 @@ def update_position(mario, tiles): n_steps = max(abs(s) for s in mario.spd) for _ in range(n_steps): mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles)) - x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps + x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps) mario.rect.topleft = x, y def get_boundaries(rect, tiles): diff --git a/index.html b/index.html index fdf254a84..0a3bb03ba 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@

- +
@@ -343,7 +343,7 @@
  • Search() and match() return None if they can't find a match.
  • Argument 'flags=re.IGNORECASE' can be used with all functions.
  • Argument 'flags=re.MULTILINE' makes '^' and '$' match the start/end of each line.
  • -
  • Argument 'flags=re.DOTALL' makes dot also accept the '\n'.
  • +
  • Argument 'flags=re.DOTALL' makes '.' also accept the '\n'.
  • Use r'\1' or '\\1' for backreference ('\1' returns a character with octal code 1).
  • Add '?' after '*' and '+' to make them non-greedy.
  • @@ -674,7 +674,7 @@

    Conditional Expression

    <obj> = <exp> if <condition> else <exp>             # Only one expression gets evaluated.
     
    -
    >>> [a if a else 'zero' for a in (0, 1, 2, 3)]
    +
    >>> [a if a else 'zero' for a in (0, 1, 2, 3)]      # `any([0, '', [], None]) == False`
     ['zero', 1, 2, 3]
     

    Named Tuple, Enum, Dataclass

    from collections import namedtuple
    @@ -683,8 +683,8 @@
     
    from enum import Enum
    -Direction = Enum('Direction', 'n e s w')            # Creates an enum.
    -direction = Direction.n                             # Returns its member.
    +Direction = Enum('Direction', 'N E S W')            # Creates an enum.
    +direction = Direction.N                             # Returns its member.
     
    from dataclasses import make_dataclass
     Player = make_dataclass('Player', ['loc', 'dir'])   # Creates a class.
    @@ -1162,9 +1162,9 @@
         index   = (members.index(member) + 1) % len(members)
         return members[index]
     
    -

    Inline

    Cutlery = Enum('Cutlery', 'fork knife spoon')
    -Cutlery = Enum('Cutlery', ['fork', 'knife', 'spoon'])
    -Cutlery = Enum('Cutlery', {'fork': 1, 'knife': 2, 'spoon': 3})
    +

    Inline

    Cutlery = Enum('Cutlery', 'FORK KNIFE SPOON')
    +Cutlery = Enum('Cutlery', ['FORK', 'KNIFE', 'SPOON'])
    +Cutlery = Enum('Cutlery', {'FORK': 1, 'KNIFE': 2, 'SPOON': 3})
     

    User-defined functions cannot be values, so they must be wrapped:

    from functools import partial
    @@ -1172,9 +1172,6 @@
                                'OR':  partial(lambda l, r: l or r)})
     
    -
      -
    • Member names are in all caps because trying to access a member that is named after a reserved keyword raises SyntaxError.
    • -

    #Exceptions

    try:
         <code>
     except <exception>:
    @@ -1780,10 +1777,10 @@ 

    Format

    # Raises queue.Empty exception if empty.

    #Operator

    Module of functions that provide the functionality of operators.

    import operator as op
    -<el>      = op.add/sub/mul/truediv/floordiv/mod(<el>, <el>)  # +, -, *, /, //, %
    -<int/set> = op.and_/or_/xor(<int/set>, <int/set>)            # &, |, ^
    -<bool>    = op.eq/ne/lt/le/gt/ge(<sortable>, <sortable>)     # ==, !=, <, <=, >, >=
    -<func>    = op.itemgetter/attrgetter/methodcaller(<obj>)     # [index/key], .name, .name()
    +<obj>     = op.add/sub/mul/truediv/floordiv/mod(<obj>, <obj>)     # +, -, *, /, //, %
    +<int/set> = op.and_/or_/xor(<int/set>, <int/set>)                 # &, |, ^
    +<bool>    = op.eq/ne/lt/le/gt/ge(<sortable>, <sortable>)          # ==, !=, <, <=, >, >=
    +<func>    = op.itemgetter/attrgetter/methodcaller(<obj> [, ...])  # [index/key], .name, .name()
     
    @@ -1861,11 +1858,11 @@

    Format

    ┏━━━━━━━━━━━━━┯━━━━━━━━━━━━━┓ ┃ Classes │ Metaclasses ┃ ┠─────────────┼─────────────┨ -┃ MyClass ──→ MyMetaClass ┃ -┃ │ ↓ ┃ -┃ object ─────→ type ←╮ ┃ -┃ │ ↑ ╰──╯ ┃ -┃ str ──────────╯ ┃ +┃ MyClass ←──╴MyMetaClass ┃ +┃ │ ↑ ┃ +┃ object ←─────╴type ←╮ ┃ +┃ │ │ ╰──╯ ┃ +┃ str ←─────────╯ ┃ ┗━━━━━━━━━━━━━┷━━━━━━━━━━━━━┛

    Inheritance Diagram

    MyClass.__base__ == object           # MyClass is a subclass of object.
    @@ -1876,9 +1873,9 @@ 

    Format

    Format

    def update_speed(mario, tiles, pressed): x, y = mario.spd x += 2 * ((D.e in pressed) - (D.w in pressed)) - x -= (x > 0) - (x < 0) + x += (x < 0) - (x > 0) y += 1 if D.s not in get_boundaries(mario.rect, tiles) else (D.n in pressed) * -10 mario.spd = P(x=max(-MAX_S.x, min(MAX_S.x, x)), y=max(-MAX_S.y, min(MAX_S.y, y))) @@ -2515,7 +2512,7 @@

    Format

    for s in mario.spd) for _ in range(n_steps): mario.spd = stop_on_collision(mario.spd, get_boundaries(mario.rect, tiles)) - x, y = x + mario.spd.x / n_steps, y + mario.spd.y / n_steps + x, y = x + (mario.spd.x / n_steps), y + (mario.spd.y / n_steps) mario.rect.topleft = x, y def get_boundaries(rect, tiles): @@ -2910,7 +2907,7 @@

    Format