理解标准输入标准输出标准错误 [英] Understanding stdin stdout stderr

查看:43
本文介绍了理解标准输入标准输出标准错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试理解 stdin stdoutstderr.

我一直看到人们在代码中使用它们,但我无法确切理解它们是什么.我假设他们与输入/输出有关,但一直在网上寻找解释却找不到.有没有人知道一个很好的解释链接,或者如果它足够简单来解释它会对我有很大的帮助.

由于我正在学习 Python 3,因此其中的示例会有所帮助.

解决方案

sys.stdin系统标准输出系统文件

解释器用于标准输入、输出和错误的文件对象:

  • stdin 用于所有交互式输入(包括对 input() 的调用);

  • stdout用于print()和表达式语句的输出和input()的提示;

  • 解释器自己的提示及其错误消息转到 stderr.

为了您的更多理解:

<预><代码>>>>导入系统>>>对于 i in (sys.stdin, sys.stdout, sys.stderr):...打印我...<在 0x103451150 处打开文件<stdin>",模式r"><打开文件'<stdout>',模式'w'在0x1034511e0><打开文件'<stderr>',模式'w'在0x103451270>

mode r 表示读取,mode w 表示写入

I'm trying to understand stdin stdout and stderr.

I see them used in people's code all the time and I can't understand exactly what they are. I am assuming that they have something to do with input/output but have been searching for an explanation online and can't find one. Does anybody know of a good link with an explanation or if it is simple enough to explain it would be a great help to me.

Since I am learning Python 3, examples in that would be helpful.

解决方案

sys.stdin
sys.stdout
sys.stderr

File objects used by the interpreter for standard input, output and errors:

  • stdin is used for all interactive input (including calls to input());

  • stdout is used for the output of print() and expression statements and for the prompts of input();

  • The interpreter’s own prompts and its error messages go to stderr.

For your more understanding:

>>> import sys
>>> for i in (sys.stdin, sys.stdout, sys.stderr):
...     print i
... 
<open file '<stdin>', mode 'r' at 0x103451150>
<open file '<stdout>', mode 'w' at 0x1034511e0>
<open file '<stderr>', mode 'w' at 0x103451270>

mode r means reading and mode w means writing

这篇关于理解标准输入标准输出标准错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆