Skip to content

Can't call next() when iterating through Query; can't iterate through QueryResultIterator #536

Description

@jcbgamboa

(I'm new to PonyORM. I understand I may be asking some nonsense)

I have a table Word, from which I'm selecting:

result = select(w for w in Word)

Then I can iterate through the table with a for loop:

for i in result:
    print(i)

This works. But if I try calling next() on result,

for i in result:
    print(i)
    # skip every second element
    a = next(result)

I get an error:

TypeError: 'Query' object is not an iterator

I thought I'd try calling iter() on result, to create an iterator. Then I can call next(result):

result = iter(result)
a = next(result)
for i in result:  # <-- will crash here
    print(i)

But then I get another error:

TypeError: 'QueryResultIterator' object is not iterable

In other words, this is an iterator that I can't iterate through (?). I am very confused about this problem.

I'm using Python3.6.8, and PonyORM 0.7.13. (let me know if you need more details)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions