summaryrefslogtreecommitdiffstats
path: root/Doc/includes
diff options
context:
space:
mode:
authorErlend Egeberg Aasland <erlend.aasland@innova.no>2022-04-16 04:21:12 (GMT)
committerGitHub <noreply@github.com>2022-04-16 04:21:12 (GMT)
commita8617566759a07c67d14c9b6ed663e32d3b3f5e7 (patch)
tree531993ba1515ca7050375c7d840579423dcc4d7f /Doc/includes
parent4e661cd69164318c1f871faa476c68a04092ddc4 (diff)
downloadcpython-a8617566759a07c67d14c9b6ed663e32d3b3f5e7.zip
cpython-a8617566759a07c67d14c9b6ed663e32d3b3f5e7.tar.gz
cpython-a8617566759a07c67d14c9b6ed663e32d3b3f5e7.tar.bz2
gh-69093: Add context manager support to sqlite3.Blob (GH-91562)
Diffstat (limited to 'Doc/includes')
-rw-r--r--Doc/includes/sqlite3/blob.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Doc/includes/sqlite3/blob.py b/Doc/includes/sqlite3/blob.py
index 61994fb..b3694ad 100644
--- a/Doc/includes/sqlite3/blob.py
+++ b/Doc/includes/sqlite3/blob.py
@@ -4,9 +4,13 @@ con = sqlite3.connect(":memory:")
con.execute("create table test(blob_col blob)")
con.execute("insert into test(blob_col) values (zeroblob(10))")
-blob = con.blobopen("test", "blob_col", 1)
-blob.write(b"Hello")
-blob.write(b"World")
-blob.seek(0)
-print(blob.read()) # will print b"HelloWorld"
-blob.close()
+# Write to our blob, using two write operations:
+with con.blobopen("test", "blob_col", 1) as blob:
+ blob.write(b"Hello")
+ blob.write(b"World")
+
+# Read the contents of our blob
+with con.blobopen("test", "blob_col", 1) as blob:
+ greeting = blob.read()
+
+print(greeting) # outputs "b'HelloWorld'"