Iterator question
Terry Reedy
tjreedy at udel.edu
Fri May 16 20:23:46 EDT 2003
"Neal D. Becker" <nbecker at hns.com> wrote in message
news:mailman.1053114567.26584.python-list at python.org...
> I was wondering if python could imitiate the c++ stl copy function,
using
> python iterators. It looks like the answer is no, because iterators
only
> support next(), and next returns an "rvalue", not an "lvalue", so
there is
> no way to assign through an iterator. Is this correct?
Yes. The intention is that iterators produce and the iteree/caller
consumes. They were specifically designed for 'for item in iterable:
...' Of course, iterators *could* produce strings for getattr() calls
or ints for indexed assignments. And you use loops in conjuction with
a class where the .next() method takes and consumes an argument (and
returns nothing). But it is less confusing to give a push method a
different name, like writeline().
Terry J. Reedy
More information about the Python-list
mailing list