【问题标题】:How to make a script think it's running using a termnal?如何让脚本认为它正在使用终端运行?
【发布时间】:2019-09-13 17:00:42
【问题描述】:

我正在使用需要使用终端运行的 python 脚本(x.py),但我有一个需要迭代的大列表,所以我做了一个可以调用 x.py 但我无法保存的脚本由于 sys.stdout.isatty() 的输出,我怎样才能让 python 脚本认为它使用atty 设备运行?

【问题讨论】:

  • think it runs using terminal 到底是什么意思?或者你可以检查here
  • @Onyambu 我想使用python IDE而不是终端运行它,我无法控制原始脚本

标签: python windows stdout tty sys


【解决方案1】:

您可以将 isatty 修改为 lambda x: True

另一个黑客在

Can you fool isatty AND log stdout and stderr separately?

【讨论】:

    【解决方案2】:

    我使用了“expect”包中的“unbuffer”。在本页搜索unbuffer:https://wiki.archlinux.org/index.php/Color_output_in_console

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-10
      • 2020-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多