[Tutor] Simple question on creating a filter

Alan Gauld alan.gauld at freenet.co.uk
Fri Feb 11 19:39:27 CET 2005

> In Perl I would do:
> while (<>)
> {
> print if line meets selection criteria;
> }

You may want to check out the fileinput module.
It takes care of multiple files being passed as input and such like

> for line in sys.stdin:
> if line meets selection criteria:
> print line

>    for line in sys.stdin:
> IOError: [Errno 9] Bad file descriptor

Sorry, I'm stumped - you did import sys I assume?

Alan G.

More information about the Tutor mailing list