Nested generators is the python equivalent of unix pipe cmds.

Steven D. Majewski sdm7g at Virginia.EDU
Fri Aug 3 22:27:38 CEST 2001


On Fri, 3 Aug 2001, Terry Reedy wrote:

> 
> I noticed the same.   A genpipe wrapping rclass would give us the very
> clear:
> 
> for f in gen(Files('.')).Test(isGif).Count(20)
> 
> My untested idea for genpipe:
    >========<

Thanks, Terry. 
Tested and corrected:

> 
> class genpipe:
>   def __init__(self, generator):
>     self.gen = generator #sanity check omitted
>   def Test(self, pred):
>     self.gen = _Test(self.gen, pred) # ditto for Count and other

-->	return self

> filters
>   def __iter__(self):

-->	return self.gen

##>     return self.gen.next


>>> for x in Genpipe( Files('.')).Test( isGif ).Count(10):
...     print x
... 
./aaTristan/usd.gif
./aaTristan/welcome_dude2.gif
./Desktop/coffee-bg.gif
./Desktop/New Dowloads/xlsappdoc/data-classes.GIF
./Desktop/New Dowloads/xlsappdoc/graph-overlay-classes.GIF
./Desktop/sdm7g-3.GIF
./Documents/Dilbert/941202.gif
./Documents/Dilbert/adding-staff.gif
./Documents/Dilbert/behind-schedule.gif
./Documents/Dilbert/d941231.gif


-- Steve 





More information about the Python-list mailing list