[Tutor] Unix philosophy
amk at amk.ca
Tue Nov 18 07:17:40 EST 2003
On Tue, Nov 18, 2003 at 12:23:49PM +0100, Guillermo Fernandez Castellanos wrote:
> That means that if I wanted to do it in a more general way that with
> fileinput module I should use the sys.stdin/out functions?
I would write it so that the library function takes any iterable for the
input, and any object with a .write() method for output. Callers could then
supply a file object, sys.stdin, or some constructed object of their own.
def process (input, output):
for line in input:
if __name__ == '__main__':
# (Or process command-line arguments to specify files...)
More information about the Tutor