sqlite3python,如何从blob中获取字节

2024-04-24 20:43:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我把我的torrent信息,从一个bencoded格式的torrent文件(由libtorrent编写)放入sqlite3数据库中的blob中,如下所示:

conn = sqlite3.connect(self.path + '/files/torrents.db')
c = conn.cursor()
q = 'UPDATE torrents SET torrent = ? WHERE name = ?'
c.execute(q, (sqlite3.Binary(data),name))
conn.commit()
conn.close()

但是,如果我使用select查询从数据库中检索blob,我得到的是一个buffer对象。。如何将其转换回我放入数据库的内容,或者更确切地说,转换成sqlite3.Binary文件 我想要我的bencoded bytes对象回来。在


Tags: 文件对象name信息数据库格式connectconn