gdbm objects not iterable?

L

Laszlo Nagy

Hi All,

gdbm objects have a "firstkey" and a "nextkey" method. So if I want
iterate through the keys (which I often do) then I have to do this:

def itergdbmkeys(gdbm_obj):
key = gdbm_obj.firstkey()
if key is None:
raise StopIteration
yield key
while True:
key = gdbm_obj.nextkey(key)
if key is None:
raise StopIteration
yield key

Then I can do this:

for key in itergdbmkeys(gdbm_obj):
process(key,gdbm_obj)

I wonder why we do not have a "next()" method, which could return an
iterator instantly. I don't think that it would be harmful, but
definitely it would be useful. Then we could do this:

for key in gdbm_obj:
process(key,obj)

I know that this is a very small change, but it can make gdbm objects
look more like dictionaries.

Please make comments. :)

Laszlo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top