简体   繁体   中英

Stdin and Stdout

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?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM