Package mms :: Module iterator :: Class PreviewIterator
[hide private]
[frames] | no frames]

Class PreviewIterator

source code

object --+
         |
        PreviewIterator

An iter wrapper class providing a "previewable" iterator.

This "preview" functionality allows the iterator to return successive values from its iterable object, without actually mvoving forward itself. This is very usefuly if the next item(s) in an iterator must be used for something, after which the iterator should "undo" those read operations, so that they can be read again by another function.

From the user point of view, this class supersedes the builtin iter() function: like iter(), it is called as PreviewIter(iterable).

Instance Methods [hide private]
 
__init__(self, *args)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__iter__(self) source code
 
next(self) source code
 
preview(self)
Return the next item in the iteratable object, but do not modify the actual iterator (i.e.
source code
 
resetPreview(self) source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Overrides: object.__init__
(inherited documentation)

preview(self)

source code 

Return the next item in the iteratable object, but do not modify the actual iterator (i.e. do not intefere with iter.next().

Successive calls to preview() will return successive values from the iterable object, exactly in the same way iter.next() does.

However, preview() will always return the next item from iterable after the item returned by the previous preview() or next() call, whichever was called the most recently. To force the "preview() iterator" to synchronize with the "next() iterator" (without calling next()), use resetPreview().