Skip to content

Commit 9edacdb

Browse files
committed
Context managers
1 parent b9b503a commit 9edacdb

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,19 @@ class MyOpen():
12041204
Hello World!
12051205
```
12061206

1207+
#### List of context managers:
1208+
```python
1209+
with open('<path>', ...) as file: ...
1210+
with wave.open('<path>', ...) as wave_file: ...
1211+
with memoryview(<bytes/bytearray/array>) as view: ...
1212+
```
1213+
1214+
#### List of reusable context managers:
1215+
```python
1216+
lock = threading.RLock(); with lock: ...
1217+
con = sqlite3.connect('<path>'); with con: con.execute('<insert_query>')
1218+
```
1219+
12071220

12081221
Enum
12091222
----

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,15 @@ <h3 id="contextmanager">Context Manager</h3>
11221122
<span class="hljs-meta">... </span> print(file.read())
11231123
Hello World!
11241124
</code></pre>
1125+
<h4 id="listofcontextmanagers">List of context managers:</h4>
1126+
<pre><code class="python language-python hljs"><span class="hljs-keyword">with</span> open(<span class="hljs-string">'&lt;path&gt;'</span>, ...) <span class="hljs-keyword">as</span> file: ...
1127+
<span class="hljs-keyword">with</span> wave.open(<span class="hljs-string">'&lt;path&gt;'</span>, ...) <span class="hljs-keyword">as</span> wave_file: ...
1128+
<span class="hljs-keyword">with</span> memoryview(&lt;bytes/bytearray/array&gt;) <span class="hljs-keyword">as</span> view: ...
1129+
</code></pre>
1130+
<h4 id="listofreusablecontextmanagers">List of reusable context managers:</h4>
1131+
<pre><code class="python language-python hljs">lock = threading.RLock(); <span class="hljs-keyword">with</span> lock: ...
1132+
con = sqlite3.connect(<span class="hljs-string">'&lt;path&gt;'</span>); <span class="hljs-keyword">with</span> con: con.execute(<span class="hljs-string">'&lt;insert_query&gt;'</span>)
1133+
</code></pre>
11251134
<h2 id="enum"><a href="#enum" name="enum">#</a>Enum</h2>
11261135
<pre><code class="python language-python hljs"><span class="hljs-keyword">from</span> enum <span class="hljs-keyword">import</span> Enum, auto
11271136

0 commit comments

Comments
 (0)