[Tutor] Unix philosophy

David Rock david at graniteweb.com
Mon Nov 17 18:53:28 EST 2003


* Kalle Svensson <kalle at lysator.liu.se> [2003-11-17 20:17]:
> Hi!
> 
> [Guillermo Fernandez Castellanos]
> > I was having a look at the UNIX philosophy and I readed that:
> > "Make every program a filter
> > This makes it easy to build a set of filter components into ``one
> > big filter.'' Programs can communicate by explicitly reading and
> > writing files; that is / much / more complex to manage, and requires
> > a lot of disk I/O for interim output. A set of filters may pass data
> > straight from memory buffer to memory buffer, avoiding disk
> > altogether."
> > 
> > I was wondering how I could be able to make my python programs work
> > in a filter mode?
> 
> Basically, what you have to do is read input from stdin and write
> output to stdout.  That makes it possible to use it as a filter in a
> pipeline like
> 
>   grep something < file | python myprog.py | lp
> 
> or whatever.  The "|" signs here connect the first program's stdout to
> the second program's stdin.

Yes, but the question is "how" to make it do that ;-) 

I use the fileinput module to do this:
   http://www.python.org/doc/current/lib/module-fileinput.html

works great for all kinds of files, multiple files, stdin, etc.

-- 
David Rock
david at graniteweb.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20031117/58616d69/attachment.bin


More information about the Tutor mailing list