Quoting Sean Perry <shaleh at speakeasy.net>: > for line in sys.stdin.readlines(): > # handle the line > > I tend to use xreadlines() which does not read the entire input at once. xreadlines() these days just does 'return self', I believe. File objects are their own iterators; you can just do: for line in sys.stdin: # do stuff -- John.