Some general questions about using "stdin","stdout"....

asdsd sir law_order_3 at hotmail.com
Thu Feb 16 09:14:58 EST 2006


Hi!I'm new in Python and i'd like to ask some general questions about 
stdin,stdout...

Firstly...

if we type like something like :
   cat "file.txt"|python somefile.py

#somefile.py
    import sys
     text=sys.stdin.read()


...then "sys.stdin.read()" will read from "cat"s stdout...
However,if i type inside a program,something like....

#someprog.py
    import sys
   print "hello"|sys.stdin.read()

.....the screen hangs..why is that?isn't the same situation as "cat"?

in addition to this...
Why can't i "write" to the stdin?
Isn't it being used as a file object like all the others?
for example
sys.stdin.close() or
open('sys.stdin','w+') or
sys.stdin.write("something") etc... don't work...

At last,let's consider "sys.stdin.read(3)"
If i type that,the program "waits" for me to type some characters,and then 
prints the first three...
However,doesn't this action actually include a "writing" to stdin and  then 
a "reading" from that?

I'm really confused...
Any help would be highly appreciated...
Thanks a lot.

_________________________________________________________________
Free blogging with MSN Spaces  http://spaces.msn.com/?mkt=nl-be




More information about the Python-list mailing list