[Twisted-Python] iterators/generator
Itamar Shtull-Trauring
twisted at itamarst.org
Mon Mar 10 08:19:42 MST 2003
On Mon, 10 Mar 2003 06:34:29 +0000
"Clark C. Evans" <cce at clarkevans.com> wrote:
> Hello. I'd like to write my 'user' level code with generators,
> and thus, was thinking that new code could perhaps be at least
> generator friendly... what do you think:
I'd rather you just use 2.1 style iterators (i.e. define a __getitem__)
in code that goes into Twisted.
class Iterator:
index = 0
def __getitem__(self, index):
if index != self.index: raise TypeError, "this is an iterator"
self.index += 1
if self.hasMoreData:
return self.getData()
else:
raise IndexError
More information about the Twisted-Python
mailing list