Why is it that *dbm modules don't provide an iterator? (Language design question)
Akira Kitada
akitada at gmail.com
Thu Apr 9 11:22:37 EDT 2009
Hi,
I was wondering why *dbm modules in Python do not give us an iterable interface?
Take a look at an example below
"""
# Python 2.6
>>> import gdbm
>>> d = gdbm.open("spam.db", "n")
>>> d["key1"] = "ham"
>>> d["key2"] = "spam"
>>>
>>> for k in d:
... print k
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'gdbm.gdbm' object is not iterable
"""
The loop has to be:
"""
>>> k = d.firstkey()
>>> while k != None:
... print k
... k = d.nextkey(k)
key2
key1
"""
I would like to know the background of this design decision.
Some research on this led me to this ticket:
http://bugs.python.org/issue662923
It looks I'm not the only one who wondered on this.
Thanks in advance.
More information about the Python-list
mailing list