I was right when I said “you can iterate an iterator only once”, but I was wrong because a SearchIterator
is not an iterator, it’s an iterable, which creates as many iterators as you need.
I wasn’t confused enough, so I decided to check the psycopg2 cursor. In this case I was sure it was an iterator, instead the documentation clearly states it’s an iterable. So I made a little test and found out it can only be used once, so it looks to me like it’s an iterator.
So:
- The
SearchIterator
described in the documentation as an iterator behaves as an iterable - The
cursor
described in the documentation as an iterable behaves as an iterator
Is my understanding of the difference between iterator and iterable wrong?