Change dbhash values in place using next() loop?

Carsten Gaebler cg at schlund.de
Sun May 27 08:27:49 EDT 2001


Hi there!

I have a DBM file with values formatted like "a:b" where a and b are
strings. Every once in a while I'd like to set a=b for every item of the
file. I tried the following:

import dbhash
db = dbhash.open("my.db", "w")
while 1:
  (k, v) = db.next()
  (a, b) = v.split(":")
  v = "%s:%s" % (b, b)
  db[k] = v


This works for about half of the items, but the others remain unchanged.
Does changing the values change the ordering of the file?

Any ideas besides looping over db.keys() (which at the moment is 16 MB in
size) or creating a temporary file and then os.system("cp -f temp.db
my.db")?

Regards
Carsten.



More information about the Python-list mailing list