This patch allows any iterable to automatically support subscripting. Simple indices (itr[n]) will consume the iterator, and return the n'th item produced. Slice indices (itr[start:stop:step]) will produce an itertools.islice object created with the appropriate arguments. It also adds the C API function PyIter_GetItem which implements the above, and is invoked by PyObject_GetItem. Built and trivially tested on Suse Linux 9.1 from current CVS. Documentation and tests still to be added (Wednesday is a public holiday, so I will hopefully get to them then).
Logged In: YES user_id=1038590 In for a penny, in for a pound. The new patch adds support for iterator concatenation (PyIter_Concat) and iterator repetition (PyIter_Repeat), based on itertools.chain and itertools.cycle respectively. The latter required adding an optional "times" argument to itertools.cycle. Augmented assignment is not supported in this patch. I also tweaked the behaviour of PyIter_GetItem, so its error handling was more like that of PySequence_GetItem. Finally, added a trivial test script that is barely deserving of the name, but does show that the thing basically works. Further work (i.e. proper tests. documentation, and cleaning up the code) will be dependent on BDFL approval.
Logged In: YES user_id=1038590 Rejecting this myself, due partially to Guido's objections, but also because I think this is better approached by offering a base class which makes syntactic manipulation of iterators more convenient (and possibly uses tee() internally).