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
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