python bsddb berkeley db 存储类型

key只允许bytes

value只允许 bytes、None

1 import bsddb3  
2 import struct
3 my_db = bsddb3.db.DB()
4 my_db.open("mydb.db",dbtype =bsddb3.db.DB_HASH,flags=bsddb3.db.DB_CREATE)
5 my_db.put("name".encode("utf-8"),"xiaoming".encode("utf-8"))
6 my_db.put("age".encode("utf-8"),struct.pack("i",22))
7 my_db.close()

 

posted @ 2018-12-30 21:43  ShaneSun  阅读(249)  评论(0编辑  收藏  举报