将python中的列表作为二进制数据(即BLOB单元)转储到sqlite3 DB中的最优雅方法是什么?
data = [ 0, 1, 2, 3, 4, 5 ]
# now write this to db as binary data
# 0000 0000
# 0000 0001
# ...
# 0000 0101
解决方法:
假设您希望将其视为8位无符号值序列,请使用阵列模块.
a = array.array('B', data)
>>> a.tostring()
'x00x01x02x03x04x05'
如果要将数据视为不同类型,请使用与“B”不同的类型代码.例如. ‘b’表示有符号字节序列,’i’表示有符号整数.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!