3 # python-cdb 0.32 "Example"
13 maker
= cdb
.cdbmake(fn
, fn
+ ".tmp");
15 maker
.add('flim', 'flam') # +4,4:flim->flam
16 maker
.add('map', 'hash') # +3,4:map->hash
17 maker
.add('spam', 'eggs') # +4,4:spam->eggs
18 maker
.add('map', 'dictionary') # +3,10:map->dictionary
19 maker
.add('map', 'assoc. array') # +3,12:map->assoc. array
21 print "Added %d records to CDB %s (fd %d)" % \
22 (maker
.numentries
, maker
.fn
, maker
.fd
)
30 c
= cdb
.init(fn
) # or init( file_obj.fileno() )
34 print c
['flim'] # 'flam'
35 print c
.get('spam') # 'eggs'
36 print c
.get('map', 0) # 'hash' -- a la cdbget utility
37 print c
.get('map', 1) # 'dictionary'
39 r
= c
.get('map') # will print:
40 while r
is not None: # 'hash'
41 print r
# 'dictionary'
42 r
= c
.getnext() # 'assoc. array'
44 print c
.keys() # ['flim', 'map', 'spam']
46 for k
in c
.keys(): # flim => ['flam']
47 print k
, '=>', c
.getall(k
) # map => ['hash', 'dictionary', 'assoc. array']
50 k
= c
.firstkey() # same as above
52 print k
, "=>", c
.getall(k
)
56 def cdbdump(cdb_o
): # as the cdbdump utility
57 r
= cdb_o
.each() # r = ('key', 'val') or None
59 print "+%d,%d:%s->%s" %
(