anydbm - a simple question
effbot at telia.com
Thu Feb 3 09:03:22 EST 2000
Randall Hopper wrote:
> |Short-term, you can patch dumbdbm.py to use int(npos-pos), but this is
> |really an interpreter bug; there's no reason 2L * 'a' should be an
> Ok, patching around this bug as you suggested, Fredrik's anydbm example
> still fails.
> >>> import anydbm
> >>> db = anydbm.open( "database", "c" )
> >>> db[ "1" ] = "one"
> >>> db.close()
> >>> db = anydbm.open( "database", "r" )
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "/home/rhh/software/python-1.5.2/lib/python1.5/anydbm.py", line 80, in open
> raise error, "need 'c' or 'n' flag to open new db"
> anydbm.error: need 'c' or 'n' flag to open new db
> It created the database.dir and database.dat files in the write phase,
> but the read phase fails on the open.
> Thinking it might be extension related I tried changing the file-to-open
> from "database" to "database.dat". But no dice:
> anydbm.error: db type could not be determined
> Same thing if I change the path to "database.dir".
> Is there another bug at work here? Or is the example flawed?
iirc, the problem is that whichdb cannot identify dumbdbm
files (the logic in anydbm.open appears to be flawed). so if
you don't have any other database on your machine, it
appears as if anydbm only provides write-once support...
More information about the Python-list