简体   繁体   English

Stdin和Stdout

[英]Stdin and Stdout

Can someone explain stdin and stdout? 有人可以解释stdin和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 . 我不明白使用这两个对象进行用户输入和输出,而不是使用printraw_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. stdinstdout是操作系统标准输入和输出的流。

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). 您可以使用它们从操作系统的std输入(通常是键盘)和输出(您的屏幕,python控制台等)读取和写入数据。

print is simply a function which writes to the operting system's stdout and adds a newline to the end. print是一个简单的函数,它写入操作系统的stdout并在末尾添加换行符。 There are more features in print than just this, but that's the basic idea. print有更多的功能,而不仅仅是这个,这是基本思想。

# 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. stdinstdout是操作系统为Python提供的标准输入和输出的流表示形式。

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. print ,其中添加换行符等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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