python print one line same space

前端 未结 4 2071
悲&欢浪女
悲&欢浪女 2021-01-26 14:06

I need to print \'ok\' in same place. Any ways to do it?

I\'ve found solutions but they don\'t works with IDLE correctly:

 while (count < 9):
      if         


        
4条回答
  •  鱼传尺愫
    2021-01-26 14:17

    That ? :

    from sys import stdout
    
    count = 1    
    statusm = "OK"
    while (count < 9):
          if statusm == "OK":
              stdout.write('OK')
              count += 1
    

    EDIT

    I think it isn't possible to do just one OK, in IDLE. But the following code will give idea of what is possible in a console:

    from sys import stdout
    from time import sleep
    
    several = ("OK",
               "bad",
               "OK",
               "bad",
               "yes",
               "OK",
               "none",
               "bad",
               "OK",
               "yes")
    
    good = ('OK','yes')
    
    for i,status in enumerate(several):
        y = str(i)
        stdout.write(y)
        stdout.write(' OK' if any(x in status for x in good) else ' --')
        sleep(1.0)
        stdout.write('\b \b\b \b\b \b')
        for c in y:  stdout.write('\b \b')
    

    result

    OKOKOKOKOKOKOKOK
    

提交回复
热议问题