如何将缓冲区读取从sqlite3转换为bitarrary

时间:2015-09-04 22:50:57

标签: python sqlite bitarray

代码:

#listElement{
background-color: #0099CC;
border:1px dashed black;
border-radius: 5px;
width:180px;
margin-bottom: 5px;
}

错误:

from bitarray import bitarray
import sqlite3

a  = bitarray('1001011')

conn = sqlite3.connect(":memory:")
# conn = sqlite3.connect('tmp.db')
cursor = conn.cursor()

cursor.execute("CREATE TABLE t (id INTEGER, x BLOB)")

cursor.execute("INSERT INTO t values (?, ?)", (1, sqlite3.Binary(a.tobytes())))
cursor.execute("select * from t")

rec = cursor.fetchone()

conn.commit()
conn.close()

b = bitarray.frombytes(rec[1])

1 个答案:

答案 0 :(得分:0)

刚想通了

 aa = bitarray()
 aa.frombytes(str(rec[1]))
 print aa
 # bitarray('10010110')
 # Please pay attention to the size, the original bitarray is 1001011,
 # but str convert it to bytes by appending a zero