【问题标题】:Print lines on top of each other in python 2.7在python 2.7中相互打印行
【发布时间】:2014-06-19 18:18:11
【问题描述】:

我想打印这样新的打印对象替换同一行中的旧打印对象。这是我的工作:

for i in range(0,10000): 
     print "\r", i,

但是这给我的结果是这样的:

9999 1415 

我希望只看到 9999。我不知道为什么它会打印出 1415。

之前有人就这个话题给出过答案,但他们一直专注于python 3.x。我有带有 Canopy 的 python 2.7。

【问题讨论】:

标签: python function printing output


【解决方案1】:

你确定吗?这是我在 Python 2.7 中的输出。效果很好

 Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> for i in range(0,10000): 
...      print "\r", i,
... 
9999 
>>> 

【讨论】:

    【解决方案2】:

    IDLE 控制台不支持 \r 覆盖已打印的字符。如果你从 shell 运行 python,这样的技术就会起作用。

    \b 也一样。你的程序没有问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-25
      • 1970-01-01
      • 2013-08-29
      • 2016-12-03
      • 1970-01-01
      • 2012-03-08
      • 2018-04-24
      • 1970-01-01
      相关资源
      最近更新 更多