【问题标题】:How to remove whitespace from an animation in Python如何在 Python 中从动画中删除空格
【发布时间】:2021-08-30 06:57:43
【问题描述】:

我已经尝试了各种方法,例如在以下代码中使用 .strip 和 textwrap.dedent:

import animation
import time

@animation.wait('spinner')
def timer_():
  time.sleep(2)
  print("test")
  return

timer_()

我想要的输出是:

test

但是输出是:

   \test

动画也以同样的方式缩进

【问题讨论】:

    标签: python whitespace indentation


    【解决方案1】:

    试试:

    import animation
    import time
    
    @animation.wait('spinner')
    def timer_():
      time.sleep(2)
      print ("\033[A  \033[A")
      print("test")
    timer_()
    

    【讨论】:

    • 我所知道的是,导入动画可以让我创建很酷的小进度条,而不是像 slowprint(" . . . . . . . ") 之类的东西。不幸的是,你的两个可能的答案都对我不起作用,让我再次“测试”。如果您对创建简单动画有任何建议,请告诉我
    • 你改变了什么,为什么?为什么原版没有按预期工作?
    • 我不确定您的“我想要的输出是:”是否足够,请在返回之前尝试 print("")。
    • @Nguyen 如果您不确定任何事情,请不要急于回答。请在评论部分进行澄清。
    • @Tibebes.M 感觉不好,
    猜你喜欢
    • 1970-01-01
    • 2022-11-05
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2012-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多