471,330 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

gdbm objects not iterable?


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

Oct 3 '07 #1
0 796

This discussion thread is closed

Replies have been disabled for this discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.