reading stdinput

Sheila King sheila at spamcop.net
Sun Mar 18 01:08:27 EST 2001


On Sun, 18 Mar 2001 11:11:00 +0930 (CST), Michael Hall <admin at mulga.com.au>
wrote in comp.lang.python in article
<mailman.984885323.10683.python-list at python.org>:

:How do I read standard input into a Python script? I'm trying to do the
:same as 'read' in a shell script to create a variable. I've played about
:with various combinations of 'sys.stdin.read()' and such but no go.

Here's a really simple little script, that reads from stdin and writes the
result to stdout. I just re-tested it now, to make sure it works:

#!/usr/bin/env python

import sys
line = sys.stdin.readline()
print line


--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list