memoryview

print(hello.encode()) # b'hello world1'
print(memoryview(hello.encode())) #<memory at 0x00000263CAD23700>
print(memoryview(hello.encode()).tobytes().decode()) #hello world1

 

 

import sqlite3

conn = sqlite3.connect('play.sqlite')
cur = conn.cursor()

cur.executescript('''
DROP TABLE IF EXISTS Play;
CREATE TABLE IF NOT EXISTS Play (
    id     INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
    txt   TEXT UNIQUE
);
''')

hello = 'hello world2'
cur.execute('INSERT OR IGNORE INTO Play (txt) VALUES (?)', (memoryview(hello.encode()),))
cur.execute('INSERT OR IGNORE INTO Play (txt) VALUES (?)', (hello,)) #跟上面那句话作用相同 很奇怪为什么那样也可以?

conn.commit()

 

 

posted @ 2022-06-18 16:42  zhishaofei3  阅读(33)  评论(0编辑  收藏  举报