Example #1
0
from lib.KyotoCabinet import DB
import kyotocabinet as kc
db = DB(mode='%')

for i in range(5): db[i] = i**2
cur = db.cursor()

while True:
    a = cur.get(True)
    if a is None: break
    key,val = a
    print key,val

class VisitorImpl(kc.Visitor):
    def visit_full(self, key, value):
        print "%s:%s" % (key, value)
        return self.NOP
    def visit_empty(self, key):
        print "%s is missing" % key
        return self.NOP

visitor = VisitorImpl()

# retrieve a record with visitor
if not db.accept(3, visitor, False):
    print "accept error: " + str(db.error())

# traverse records with visitor
if not db.iterate(visitor, False):
    print "iterate error: " + str(db.error())