From: "Oren Tirosh" <oren-py-d@hishome.net> > On Tue, Jul 09, 2002 at 04:43:25AM -0400, David Abrahams wrote: > > Yep. [Part of the reason I want to know whether I've got a one-shot > > sequence is that inspecting that sequence then becomes an > > information-destroying operation -- only being able to touch it once > > changes how you have to handle it] > > > > I was thinking one potentially nice way to introspect about > > multi-pass-ability might be to get an iterator and to see whether it was > > copyable. Currently even most multi-pass iterators can't be copied with > > copy.copy(). > > I wouldn't call it a one-shot sequence - it's just an iterator. The name > iterator is enough to suggest that it is disposable and good for just one > pass through the container. > > If the object has an __iter__ method but no next it's not an iterator and > therefore most likely re-iterable. One notable exception is a file object. > File iterators affect the current position of the file. No kidding, that's the problem I'm talking about. It does me no good to have a criterion for determinining re-iterability which fails for the case I'm most concerned with ;-) > If you think about > it you'll see that file objects aren't really containers - they are already > iterators. The real container is the file on the disk There might not be a "real container" -- if it's an input pipe the data disappears as you iterate it. -Dave
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4