【问题标题】:Carriage return has a different behavior in Eclipse and in the command prompt回车在 Eclipse 和命令提示符中具有不同的行为
【发布时间】:2017-03-25 12:19:47
【问题描述】:

当我在 Windows 命令提示符或 Linux 终端中运行以下 python 3 代码时:

for i in range (10):
    print('Step {0}'.format(i), end='\r', flush=True)
print('everything is done', flush=True)

输出是:

everything is done

但是,当我在 Eclipse 中运行相同的代码时,输​​出是:

Step 0
Step 1
Step 2
Step 3
Step 4
Step 5
Step 6
Step 7
Step 8
Step 9
everything is done

这能解释什么?

我使用 Eclipse 标准/SDK,版本:Kepler 版本,内部版本号:20130614-0229。

【问题讨论】:

    标签: python eclipse carriage-return


    【解决方案1】:

    听起来 Eclipse 正在尝试提供帮助并将 \r 转换为 \r\n。像 Eclipse 这样在多个平台上运行的应用程序,这并不奇怪。

    一种可能的解决方法是发送大量退格而不是单个 \r。 (是的,这很丑陋且不方便,但它可能会完成工作。)一般来说,覆盖控制台输出是一个不确定的提议,您的结果会因上下文而异。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2020-03-21
      相关资源
      最近更新 更多