为什么sys.stderr和sys.stdout将数字放在外壳的末尾,而不是在模块的末尾-python

U10转发

基本上我的问题是标题

例如在shell中:

>>> import sys
>>> sys.stdout.write('Hello')
Hello5

(与相同stderr

但是从文件中:

import sys
sys.stdout.write('Hello')

输出:

Hello

(与相同stderr

那么为什么会这样呢?

user2357112支持Monica

那就是返回值。sys.stdout.write('Hello')返回5,它会以交互方式自动打印,但不会以脚本方式打印。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在python中了解sys.stdout和sys.stderr

为什么`subprocess.check_call(...,stderr = sys.stdout)`在Python 2.6中失败?

将Loggers的消息重定向到sys.stdout和sys.stderr

为什么 sys.stdout(在 python 中)没有恢复到默认值的默认方法

为什么未在Python 3的“ sys.modules”中导入模块?

为什么需要使用“ import”语句显式导入“内置” python模块“ sys”?

python捕获其他模块产生的sys.stdout和sys.exit

为什么sys.stdout = None不起作用?

为什么sys.stdout.write输出意外字符?

为什么不能在sys.path中导入模块?

何时使用sys.stdout代替sys.stderr?

为什么在带有 python3 内核的 jupyter-notebook 中,sys.version 显示 2.7.2,而不是 python3.x

使用模块 os 和 sys 在 python 中索引错误

为什么我在使用sys.stdout()打印后得到310,而不是只有3?

python和sys.argv

sys.stdout.encoding,locale.getpreferredencoding()和sys.getdefaultencoding()有什么区别?

未处理异常的错误回溯消息在哪里写 - sys.stdout 或 sys.stderr 或其他地方?(在 Python 中)

为什么Python sys.version_info缺少_asdict()方法以转换为dict?

为什么在 Python 调用 sys.exit 时 upstart 服务没有停止

为什么在Python的线程内调用sys.exit()时不退出?

当有后台线程时,为什么 sys.exit() 不会关闭 python?

为什么我不能连续两次在sys.stdin中执行循环?(Python)

空python进程挂在连接[sys.stderr.flush()]上

pip:sys.stderr.write(f“ ERROR:{exc}”)with Python 3.5

Windows CMD在python的sys.stdout打印行的末尾添加一个随机数

python3中的sys.stdout.write在字符串末尾添加11

为什么我不能使用“ from sys import stdout”重定向STDOUT?

为什么哪个和Sys。哪个返回不同的路径?

为什么/ proc和/ sys具有inode 1?