From 79871494134de310d1f09b37d93b66f19bee91b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Sun, 26 Apr 2020 00:54:25 +0200 Subject: [PATCH] Small fixes --- README.md | 22 +++++++++------------- index.html | 23 +++++++++++------------ pdf/index_for_pdf.html | 2 +- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index b4513ed..4c1354c 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,6 @@ Iterator = list() # Returns a list of iterator's remaining elements. ``` - ### Itertools ```python from itertools import count, repeat, cycle, chain, islice @@ -256,7 +255,7 @@ Type (, , ) ``` -#### Some types do not have built-in names, so they must be imported: +#### Some types don't have built-in names, so they must be imported: ```python from types import FunctionType, MethodType, LambdaType, GeneratorType ``` @@ -469,7 +468,7 @@ Format +---------------+-----------------+-----------------+-----------------+-----------------+ ``` -### Ints +### Integers ```python {90:c} # 'Z' {90:b} # '1011010' @@ -852,7 +851,7 @@ from functools import partial * **Partial is also useful in cases when function needs to be passed as an argument, because it enables us to set its arguments beforehand.** * **A few examples being: `'defaultdict()'`, `'iter(, to_exclusive)'` and dataclass's `'field(default_factory=)'`.** -### Nonlocal +### Non-Local **If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.** ```python @@ -1499,7 +1498,7 @@ script_name = sys.argv[0] arguments = sys.argv[1:] ``` -### Argparse +### Argument Parser ```python from argparse import ArgumentParser, FileType p = ArgumentParser(description=) @@ -2141,9 +2140,6 @@ Introspection ```python = dir() # Names of object's attributes (incl. methods). = vars() # Dict of object's fields. Also .__dict__. -``` - -```python = hasattr(, '') value = getattr(, '') setattr(, '', value) @@ -2284,10 +2280,10 @@ def main(screen): async def main_coroutine(screen): state = {'*': P(0, 0), **{id_: P(30, 10) for id_ in range(10)}} moves = asyncio.Queue() - coros = (*(random_controller(id_, moves) for id_ in range(10)), + coros = [*[random_controller(id_, moves) for id_ in range(10)], human_controller(screen, moves), model(moves, state, *screen.getmaxyx()), - view(state, screen)) + view(state, screen)] await asyncio.wait(coros, return_when=asyncio.FIRST_COMPLETED) async def random_controller(id_, moves): @@ -2929,7 +2925,7 @@ while all(event.type != pg.QUIT for event in pg.event.get()): pg.display.flip() ``` -### Rect +### Rectangle **Object for storing rectangular coordinates.** ```python = pg.Rect(x, y, width, height) @@ -2987,9 +2983,9 @@ pg.draw.ellipse(, color, ) .play() # Starts playing the sound. ``` -### Super Mario Bros. Example +### Basic Mario Brothers Example ```python -import collections, dataclasses, enum, io, math, pygame, urllib.request, itertools as it +import collections, dataclasses, enum, io, pygame, urllib.request, itertools as it from random import randint P = collections.namedtuple('P', 'x y') # Position diff --git a/index.html b/index.html index d4c6035..fec3e5f 100644 --- a/index.html +++ b/index.html @@ -389,7 +389,7 @@ to_exclusive = <range>.stop
>>> type('a'), 'a'.__class__, str
 (<class 'str'>, <class 'str'>, <class 'str'>)
 
-

Some types do not have built-in names, so they must be imported:

from types import FunctionType, MethodType, LambdaType, GeneratorType
+

Some types don't have built-in names, so they must be imported:

from types import FunctionType, MethodType, LambdaType, GeneratorType
 

Abstract Base Classes

Each abstract base class specifies a set of virtual subclasses. These classes are then recognized by isinstance() and issubclass() as subclasses of the ABC, although they are really not.

>>> from collections.abc import Sequence, Collection, Iterable
@@ -559,7 +559,7 @@ to_exclusive   = <range>.stop
 | 567.89        |    '5.7e+02'    |     '567.89'    |    '5.68e+02'   |   '56789.00%'   |
 +---------------+-----------------+-----------------+-----------------+-----------------+
 
-

Ints

{90:c}                                # 'Z'
+

Integers

{90:c}                                # 'Z'
 {90:b}                                # '1011010'
 {90:X}                                # '5A'
 
@@ -846,7 +846,7 @@ creature = Creature(Point(0, 'defaultdict(<function>)'
, 'iter(<function>, to_exclusive)' and dataclass's 'field(default_factory=<function>)'. -

Nonlocal

If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.

def get_counter():
+

Non-Local

If variable is being assigned to anywhere in the scope, it is regarded as a local variable, unless it is declared as a 'global' or a 'nonlocal'.

def get_counter():
     i = 0
     def out():
         nonlocal i
@@ -1394,7 +1394,7 @@ script_name = sys.argv[0]
 arguments   = sys.argv[1:]
 
-

Argparse

from argparse import ArgumentParser, FileType
+

Argument Parser

from argparse import ArgumentParser, FileType
 p = ArgumentParser(description=<str>)
 p.add_argument('-<short_name>', '--<name>', action='store_true')  # Flag
 p.add_argument('-<short_name>', '--<name>', type=<type>)          # Option
@@ -1876,13 +1876,12 @@ last_el          = op.methodcaller('pop')(<l
 
 

Attributes

<list> = dir(<object>)                     # Names of object's attributes (incl. methods).
 <dict> = vars(<object>)                    # Dict of object's fields. Also <obj>.__dict__.
-
- -
<bool> = hasattr(<object>, '<attr_name>')
+<bool> = hasattr(<object>, '<attr_name>')
 value  = getattr(<object>, '<attr_name>')
 setattr(<object>, '<attr_name>', value)
 delattr(<object>, '<attr_name>')
-
+
+

Parameters

from inspect import signature
 <sig>        = signature(<function>)
 no_of_params = len(<sig>.parameters)
@@ -1980,10 +1979,10 @@ D = enum.Enum('D', 'n
 async def main_coroutine(screen):
     state = {'*': P(0, 0), **{id_: P(30, 10) for id_ in range(10)}}
     moves = asyncio.Queue()
-    coros = (*(random_controller(id_, moves) for id_ in range(10)),
+    coros = [*[random_controller(id_, moves) for id_ in range(10)],
              human_controller(screen, moves),
              model(moves, state, *screen.getmaxyx()),
-             view(state, screen))
+             view(state, screen)]
     await asyncio.wait(coros, return_when=asyncio.FIRST_COMPLETED)
 
 async def random_controller(id_, moves):
@@ -2493,7 +2492,7 @@ rect = pg.Rect(240, 2
 
-

Rect

Object for storing rectangular coordinates.

<Rect> = pg.Rect(x, y, width, height)
+

Rectangle

Object for storing rectangular coordinates.

<Rect> = pg.Rect(x, y, width, height)
 <int>  = <Rect>.x/y/centerx/centery/…
 <tup.> = <Rect>.topleft/center/…
 <Rect> = <Rect>.move((x, y))
@@ -2535,7 +2534,7 @@ pg.draw.ellipse(<Surf>, color, <Rect>)
 <Sound>.play()                                  # Starts playing the sound.
 
-

Super Mario Bros. Example

import collections, dataclasses, enum, io, math, pygame, urllib.request, itertools as it
+

Basic Mario Brothers Example

import collections, dataclasses, enum, io, pygame, urllib.request, itertools as it
 from random import randint
 
 P = collections.namedtuple('P', 'x y')          # Position
diff --git a/pdf/index_for_pdf.html b/pdf/index_for_pdf.html
index ce18771..2c78c79 100644
--- a/pdf/index_for_pdf.html
+++ b/pdf/index_for_pdf.html
@@ -10,7 +10,7 @@
 all function, 11
animation, 40
any function, 11
-argparse module, 22
+argparse module, 22
arguments, 10
arrays, 29
audio, 40-41