Can someone explain stdin and stdout? I don't understand what is the difference between using these two objects for user input and output as opposed to print and raw_input. Perhaps there is some vital information I am missing. Can anyone explain?
2 Answers
stdin and stdout are the streams for your operating system's standard input and output.
You use them to read and write data from your operating system's std input (usually keyboard) and output (your screen, the python console, or such).
print is simply a function which writes to the operting system's stdout and adds a newline to the end. There are more features in print than just this, but that's the basic idea.
# Simplified print implementation def print(value, end='\n'): stdout.write(value) stdout.write(end) Comments
stdin and stdout are stream representations of the standard in- and output that your OS supplies Python with.
You can do almost everything you can do with a file on these, so for many applications, they are far more useful than eg. print, which adds linebreaks etc.
7 Comments
stdin and stdout in a Java program per say and then access this data in Python?file().stdin and stdout in Python subprocesses? What does that do?p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)