diff --git a/README.md b/README.md index 960e795..50e1b98 100644 --- a/README.md +++ b/README.md @@ -772,7 +772,7 @@ Inline = filter(lambda x: x > 5, range(10)) # (6, 7, 8, 9) = reduce(lambda out, x: out + x, range(10)) # 45 ``` -* **Reduce must be imported from functools module.** +* **Reduce must be imported from the functools module.** ### Any, All ```python @@ -1043,11 +1043,10 @@ class : : = : list/dict/set = field(default_factory=list/dict/set) ``` -* **For arbitrary type use `'typing.Any'`.** * **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 `': list = []'` would make a list that is shared among all instances.** -* **Default_factory can be any [callable](#callable).** +* **Function field() is needed because `': list = []'` would make a list that is shared among all instances. Argument 'default_factory' can be any [callable](#callable).** +* **For attributes of arbitrary type use `'typing.Any'`.** #### Inline: ```python @@ -1245,7 +1244,7 @@ class MyCollection: ### Sequence * **Only required methods are len() and getitem().** -* **Getitem() should return an item at index or raise IndexError.** +* **Getitem() should return an item at the passed index or raise IndexError.** * **Iter() and contains() automatically work on any object that has getitem() defined.** * **Reversed() automatically works on any object that has len() and getitem() defined.** ```python @@ -1646,7 +1645,7 @@ from pathlib import Path ```python = Path( [, ...]) # Accepts strings, Paths and DirEntry objects. - = / [/ ...] # One of the paths must be a Path object. + = / [/ ...] # One of the two paths must be a Path object. ``` ```python @@ -2498,22 +2497,22 @@ run(host='0.0.0.0', port=80) # Runs globally. ### Static Request ```python -@route('/img/') -def send_image(image): - return static_file(image, 'img_dir/', mimetype='image/png') +@route('/img/') +def send_file(filename): + return static_file(filename, root='img_dir/') ``` ### Dynamic Request ```python @route('/') -def send_page(sport): +def send_html(sport): return template('

{{title}}

', title=sport) ``` ### REST Request ```python @post('//odds') -def odds_handler(sport): +def send_json(sport): team = request.forms.get('team') home_odds, away_odds = 2.44, 3.29 response.headers['Content-Type'] = 'application/json' @@ -2766,16 +2765,17 @@ from PIL import ImageDraw ``` ```python -.point((x, y), fill=None) -.line((x1, y1, x2, y2 [, ...]), fill=None, width=0, joint=None) -.arc((x1, y1, x2, y2), from_deg, to_deg, fill=None, width=0) -.rectangle((x1, y1, x2, y2), fill=None, outline=None, width=0) -.polygon((x1, y1, x2, y2 [, ...]), fill=None, outline=None) -.ellipse((x1, y1, x2, y2), fill=None, outline=None, width=0) +.point((x, y)) +.line((x1, y1, x2, y2 [, ...])) +.arc((x1, y1, x2, y2), from_deg, to_deg) +.rectangle((x1, y1, x2, y2)) +.polygon((x1, y1, x2, y2 [, ...])) +.ellipse((x1, y1, x2, y2)) ``` * **Use `'fill='` to set the primary color.** -* **Use `'outline='` to set the secondary color.** -* **Color can be specified as an int, tuple, `'#rrggbb[aa]'` string or a color name.** +* **Use `'width='` to set the width of lines or contours.** +* **Use `'outline='` to set the color of the contours.** +* **Colors can be specified as an int, tuple, `'#rrggbb[aa]'` string or a color name.** Animation diff --git a/index.html b/index.html index 85803a8..ddf7194 100644 --- a/index.html +++ b/index.html @@ -226,7 +226,7 @@ pre.prettyprint {
- +
@@ -816,7 +816,7 @@ func(*args, **kwargs)
    -
  • Reduce must be imported from functools module.
  • +
  • Reduce must be imported from the functools module.

Any, All

<bool> = any(<collection>)                                # Is `bool(el)` True for any element.
 <bool> = all(<collection>)                                # Is True for all elements or empty.
@@ -1035,11 +1035,10 @@ Z = dataclasses.make_dataclass('Z', [
-
  • For arbitrary type use 'typing.Any'.
  • 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.
  • -
  • Default_factory can be any callable.
  • +
  • Function field() is needed because '<attr_name>: list = []' would make a list that is shared among all instances. Argument 'default_factory' can be any callable.
  • +
  • For attributes of arbitrary type use 'typing.Any'.
  • Inline:

    from dataclasses import make_dataclass
     <class> = make_dataclass('<class_name>', <coll_of_attribute_names>)
    @@ -1215,7 +1214,7 @@ Hello World!
     
     

    Sequence

    • Only required methods are len() and getitem().
    • -
    • Getitem() should return an item at index or raise IndexError.
    • +
    • Getitem() should return an item at the passed index or raise IndexError.
    • Iter() and contains() automatically work on any object that has getitem() defined.
    • Reversed() automatically works on any object that has len() and getitem() defined.
    class MySequence:
    @@ -1543,7 +1542,7 @@ value = args.<name>
     
    <Path> = Path(<path> [, ...])       # Accepts strings, Paths and DirEntry objects.
    -<Path> = <path> / <path> [/ ...]    # One of the paths must be a Path object.
    +<Path> = <path> / <path> [/ ...]    # One of the two paths must be a Path object.
     
    <Path> = Path()                     # Returns relative cwd. Also Path('.').
     <Path> = Path.cwd()                 # Returns absolute cwd. Also Path().resolve().
    @@ -2188,18 +2187,18 @@ WIKI_URL = 'https://en.wikipedia.org/wiki/Python_(prog
     run(host='0.0.0.0', port=80)            # Runs globally.
     
    -

    Static Request

    @route('/img/<image>')
    -def send_image(image):
    -    return static_file(image, 'img_dir/', mimetype='image/png')
    +

    Static Request

    @route('/img/<filename>')
    +def send_file(filename):
    +    return static_file(filename, root='img_dir/')
     

    Dynamic Request

    @route('/<sport>')
    -def send_page(sport):
    +def send_html(sport):
         return template('<h1>{{title}}</h1>', title=sport)
     

    REST Request

    @post('/<sport>/odds')
    -def odds_handler(sport):
    +def send_json(sport):
         team = request.forms.get('team')
         home_odds, away_odds = 2.44, 3.29
         response.headers['Content-Type'] = 'application/json'
    @@ -2390,17 +2389,18 @@ img.convert('RGB').save(<ImageDraw>.point((x, y), fill=None)
    -<ImageDraw>.line((x1, y1, x2, y2 [, ...]), fill=None, width=0, joint=None) 
    -<ImageDraw>.arc((x1, y1, x2, y2), from_deg, to_deg, fill=None, width=0)
    -<ImageDraw>.rectangle((x1, y1, x2, y2), fill=None, outline=None, width=0)
    -<ImageDraw>.polygon((x1, y1, x2, y2 [, ...]), fill=None, outline=None)
    -<ImageDraw>.ellipse((x1, y1, x2, y2), fill=None, outline=None, width=0)
    +
    <ImageDraw>.point((x, y))
    +<ImageDraw>.line((x1, y1, x2, y2 [, ...]))
    +<ImageDraw>.arc((x1, y1, x2, y2), from_deg, to_deg)
    +<ImageDraw>.rectangle((x1, y1, x2, y2))
    +<ImageDraw>.polygon((x1, y1, x2, y2 [, ...]))
    +<ImageDraw>.ellipse((x1, y1, x2, y2))
     
    • Use 'fill=<color>' to set the primary color.
    • -
    • Use 'outline=<color>' to set the secondary color.
    • -
    • Color can be specified as an int, tuple, '#rrggbb[aa]' string or a color name.
    • +
    • Use 'width=<int>' to set the width of lines or contours.
    • +
    • Use 'outline=<color>' to set the color of the contours.
    • +
    • Colors can be specified as an int, tuple, '#rrggbb[aa]' string or a color name.

    #Animation

    Creates a GIF of a bouncing ball:

    # $ pip3 install imageio
     from PIL import Image, ImageDraw
    @@ -3017,7 +3017,7 @@ $ pyinstaller script.py --add-data '<path>:.'