Some general questions about using "stdin","stdout"....
Dan
dan at cellectivity.com
Thu Feb 16 10:16:29 EST 2006
Hello.
If you're new to Python, then input/output isn't the best place to
start. Begin with the tutorial:
http://docs.python.org/tut/tut.html
Other documentation is also linked to from there.
However, I will briefly answer your questions.
> print "hello"|sys.stdin.read()
In Python the | operator has a different meaning than in a shell. In
Python it means "bitwise or":
>>> print 5 | 9
13
> Why can't i "write" to the stdin?
There may be some contorted way to do that under Unix, but it's not a
good idea. You can pipe input to your program from a shell (as you've
already done), but it's not a good idea to redirect input from within
your program.
You can accomplish the same thing like this:
if i_want_to_redirect_input:
my_input_source = open('file.txt')
else:
my_input_source = sys.stdin
# Now read from my_input_source instead of stdin.
--
They had a big meeting, drank some beer and had some pizza and
decided 'A' would be 65.
- Jim Greenly, professor at Georgia Institute of Technology
More information about the Python-list
mailing list