Few questions about new features in Python 2.2
Ignacio Vazquez-Abrams
ignacio at openservices.net
Tue Oct 23 04:32:56 EDT 2001
On 23 Oct 2001, sebastien wrote:
> Why iterators can't be copied?
> -----------------------------
> Something like:
> MyIter = iter([1,2,3,4])
> MyIter2 = iter(MyIter)
> doesn't provide a copy but a reference to the iterator
> And that:
> import copy
> MyIter2 = copy.copy(MyIter)
> Just doesn't work
>
> But you can have the need to save an iterator position when you want
> to try something and
> retry other thing if the first attempt fail.
> For sample I think Tim recipe for removing duplicate would need copy
> to work with iterator.
An iterator/generator isn't an object; it's a concept of object behavior. It's
a side effect of an actual object "yield"ing a value.
--
Ignacio Vazquez-Abrams <ignacio at openservices.net>
"As far as I can tell / It doesn't matter who you are /
If you can believe there's something worth fighting for."
- "Parade", Garbage
More information about the Python-list
mailing list