diff --git a/README.md b/README.md index 11823d0..a822351 100644 --- a/README.md +++ b/README.md @@ -1043,7 +1043,7 @@ class : : list/dict/set = field(default_factory=list/dict/set) ``` * **Objects can be made sortable with `'order=True'` and immutable with `'frozen=True'`.** -* **For object to be hashable, all attributes must be [hashable](#hashable) and frozen must be 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. Its 'default_factory' argument can be any [callable](#callable).** * **For attributes of arbitrary type use `'typing.Any'`.** @@ -2475,7 +2475,7 @@ Scraping #### Scrapes Python's URL, version number and logo from its Wikipedia page: ```python # $ pip3 install requests beautifulsoup4 -import requests, bs4, sys +import requests, bs4, os, sys WIKI_URL = 'https://en.wikipedia.org/wiki/Python_(programming_language)' try: @@ -2486,9 +2486,10 @@ try: version = table.find('th', text='Stable release').next_sibling.strings.__next__() logo_url = table.find('img')['src'] logo = requests.get(f'https:{logo_url}').content - with open('test.png', 'wb') as file: + filename = os.path.basename(logo_url) + with open(filename, 'wb') as file: file.write(logo) - print(python_url, version) + print(f'{python_url}, {version}, file://{os.path.abspath(filename)}') except requests.exceptions.ConnectionError: print("You've got problems with connection.", file=sys.stderr) ``` diff --git a/index.html b/index.html index e0906ba..278a4f5 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -886,7 +886,7 @@ Z = dataclasses.make_dataclass('Z', [
  • Objects can be made sortable with 'order=True' and immutable with 'frozen=True'.
  • -
  • For object to be hashable, all attributes must be hashable and frozen must be True.
  • +
  • For object to be hashable, all attributes must be hashable and 'frozen' must be True.
  • Function field() is needed because '<attr_name>: list = []' would make a list that is shared among all instances. Its 'default_factory' argument can be any callable.
  • For attributes of arbitrary type use 'typing.Any'.
  • @@ -2023,7 +2023,7 @@ logger.<level>('A logging message.')
  • '<str>' - Max age as a string: '1 week, 3 days', '2 months', …
  • #Scraping

    Scrapes Python's URL, version number and logo from its Wikipedia page:

    # $ pip3 install requests beautifulsoup4
    -import requests, bs4, sys
    +import requests, bs4, os, sys
     
     WIKI_URL = 'https://en.wikipedia.org/wiki/Python_(programming_language)'
     try:
    @@ -2034,9 +2034,10 @@ WIKI_URL = 'https://en.wikipedia.org/wiki/Python_(prog
         version    = table.find('th', text='Stable release').next_sibling.strings.__next__()
         logo_url   = table.find('img')['src']
         logo       = requests.get(f'https:{logo_url}').content
    -    with open('test.png', 'wb') as file:
    +    filename   = os.path.basename(logo_url)
    +    with open(filename, 'wb') as file:
             file.write(logo)
    -    print(python_url, version)
    +    print(f'{python_url}, {version}, file://{os.path.abspath(filename)}')
     except requests.exceptions.ConnectionError:
         print("You've got problems with connection.", file=sys.stderr)
     
    @@ -2881,7 +2882,7 @@ $ pyinstaller script.py --add-data '<path>:.'
    - +
    diff --git a/pdf/remove_links.py b/pdf/remove_links.py index e46c0b8..8a35856 100755 --- a/pdf/remove_links.py +++ b/pdf/remove_links.py @@ -11,7 +11,6 @@ MATCHES = { 'Module operator provides functions itemgetter() and mul() that offer the same functionality as lambda expressions above.': 'Module \'operator\' (p. 31) provides functions itemgetter() and mul() that offer the same functionality as lambda expressions (p. 11) above.', 'Adding \'!r\' before the colon converts object to string by calling its repr() method.': 'Adding \'!r\' before the colon converts object to string by calling its repr() method (p. 14).', 'It can be any callable, but is usually implemented as a function that returns a closure.': 'It can be any callable (p. 17), but is usually implemented as a function that returns a closure (p. 12).', - 'For object to be hashable, all attributes must be hashable and frozen must be True.': 'For object to be hashable, all attributes must be hashable (p. 16) and frozen must be True.', 'Function field() is needed because \'<attr_name>: list = []\' would make a list that is shared among all instances. Its \'default_factory\' argument can be any callable.': 'Function field() is needed because \'<attr_name>: list = []\' would make a list that is shared among all instances. Its \'default_factory\' argument can be any callable (p. 17).', 'Sequence iterators returned by the iter() function, such as list_iterator and set_iterator.': 'Sequence iterators returned by the iter() function, such as list_iterator and set_iterator (p. 3).', 'Objects returned by the itertools module, such as count, repeat and cycle.': 'Objects returned by the itertools module, such as count, repeat and cycle (p. 3).',