From 29afb7d2efed6ee48a67dafdc1a1f34dd60153cf Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Fri, 22 Apr 2022 03:45:16 +0200 Subject: gh-69093: Add indexing and slicing support to sqlite3.Blob (#91599) Authored-by: Aviv Palivoda Co-authored-by: Erlend E. Aasland --- Doc/includes/sqlite3/blob.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'Doc/includes/sqlite3/blob.py') diff --git a/Doc/includes/sqlite3/blob.py b/Doc/includes/sqlite3/blob.py index b3694ad08a..d947059b3a 100644 --- a/Doc/includes/sqlite3/blob.py +++ b/Doc/includes/sqlite3/blob.py @@ -2,15 +2,18 @@ import sqlite3 con = sqlite3.connect(":memory:") con.execute("create table test(blob_col blob)") -con.execute("insert into test(blob_col) values (zeroblob(10))") +con.execute("insert into test(blob_col) values (zeroblob(13))") # 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") + blob.write(b"hello, ") + blob.write(b"world.") + # Modify the first and last bytes of our blob + blob[0] = b"H" + blob[-1] = b"!" # Read the contents of our blob with con.blobopen("test", "blob_col", 1) as blob: greeting = blob.read() -print(greeting) # outputs "b'HelloWorld'" +print(greeting) # outputs "b'Hello, world!'" -- cgit v1.2.1