From 9edacdb114206529c3654c6655ce65c906d2b570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Thu, 4 Jul 2019 19:36:07 +0200 Subject: [PATCH] Context managers --- README.md | 13 +++++++++++++ index.html | 9 +++++++++ 2 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 020bab5..44ca1f4 100644 --- a/README.md +++ b/README.md @@ -1204,6 +1204,19 @@ class MyOpen(): Hello World! ``` +#### List of context managers: +```python +with open('', ...) as file: ... +with wave.open('', ...) as wave_file: ... +with memoryview() as view: ... +``` + +#### List of reusable context managers: +```python +lock = threading.RLock(); with lock: ... +con = sqlite3.connect(''); with con: con.execute('') +``` + Enum ---- diff --git a/index.html b/index.html index 8f19505..feb9e7a 100644 --- a/index.html +++ b/index.html @@ -1122,6 +1122,15 @@ Z = dataclasses.make_dataclass('Z', [... print(file.read()) Hello World! +

List of context managers:

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

List of reusable context managers:

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

#Enum

from enum import Enum, auto