diff --git a/README.md b/README.md index 0009fc7..d03d436 100644 --- a/README.md +++ b/README.md @@ -1154,17 +1154,13 @@ class MyOpen(): Hello World! ``` -#### Context managers: +#### List of existing context managers: ```python with open('', ...) as file: ... with wave.open('', ...) as wave_file: ... with memoryview() as view: ... -``` - -#### Reusable context managers: -```python +db = sqlite3.connect(''); with db: db.execute('') lock = threading.RLock(); with lock: ... -con = sqlite3.connect(''); with con: con.execute('') ``` @@ -1232,6 +1228,7 @@ class MySequence: * **It's a richer interface than the basic sequence.** * **Extending it generates iter(), contains(), reversed(), index(), and count().** * **Unlike `'abc.Iterable'` and `'abc.Collection'`, it is not a duck type. That is why `'issubclass(MySequence, collections.abc.Sequence)'` would return 'False' even if it had all the methods defined.** + ```python class MyAbcSequence(collections.abc.Sequence): def __init__(self, a): @@ -1258,6 +1255,8 @@ class MyAbcSequence(collections.abc.Sequence): +------------+----------+------------+----------+--------------+ ``` +* **Other useful ABCs that automatically generate missing methods are: MutableSequence, Set, MutableSet, Mapping and MutableMapping.** + Enum ---- diff --git a/index.html b/index.html index bdd009b..4460f54 100644 --- a/index.html +++ b/index.html @@ -1075,14 +1075,12 @@ Z = dataclasses.make_dataclass('Z', [... print(file.read()) Hello World! -

Context managers:

+

List of existing context managers:

with open('<path>', ...) as file: ...
 with wave.open('<path>', ...) as wave_file: ...
 with memoryview(<bytes/bytearray/array>) as view: ...
-
-

Reusable context managers:

-
lock = threading.RLock(); with lock: ...
-con  = sqlite3.connect('<path>'); with con: con.execute('<insert_query>')
+db = sqlite3.connect('<path>'); with db: db.execute('<insert_query>')
+lock = threading.RLock(); with lock: ...
 

#Iterable Duck Types

Iterable

@@ -1168,6 +1166,9 @@ con = sqlite3.connect('<path>'); +
    +
  • Other useful ABCs that automatically generate missing methods are: MutableSequence, Set, MutableSet, Mapping and MutableMapping.
  • +

#Enum

from enum import Enum, auto