1

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?

0

2 Answers 2

3

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) 
Sign up to request clarification or add additional context in comments.

Comments

1

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

And are they just for console input and output, or can they be used with files and pipes? If so how is that done? Can one use stdin and stdout in a Java program per say and then access this data in Python?
@MalikBrahimi They are for the console. Write the stuff to a file in Java, and then read (or write) it on python using file().
And why do people pass stdin and stdout in Python subprocesses? What does that do?
Having these streams available in subprocesses that otherwise might have no access to your standard in/output ?!
Straight from the docs: p2 = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.