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()