I’m attempting a pretty cut & dry example of anydbm:
#!/usr/bin/python
import anydbm
# Open database, creating it if necessary.
db = anydbm.open('cache', 'c')
# Record some values
db['www.python.org'] = 'Python Website'
db['www.cnn.com'] = 'Cable News Network'
for k, v in db.iteritems():
print k, '\t', v
Yet, on my machine (OS X 10.5.8, Python 2.5.1), I get the following error:
Traceback (most recent call last):
File “./foo.py”, line 12, in
for k, v in db.iteritems():
AttributeError: iteritems
Any suggestions?
It appears the Apple-supplied Pythons are not built with any third-party database libraries so
anydbmresults in the use of the default portabledumbdbmimplementation which lacks aniteritemsmethod.The python.org OS X Pythons, on the other hand, are built with a real dbm interface:
There are some open issues on the Python bug tracker concerning some of the dbm modules inconsistencies.