[英]How do I delete&replace multiple printed lines using python with cmd? [on hold]
I tried to run this code:我试图运行这段代码:
hello = """ _ _
| | | |
| |__| |
| __ |
| | | |
|_| |_|"""
for char in range(len(hello)):
print (hello[:char])
time.sleep(0.05)
I wanted to delete everything that was printed in the end of each iteration.我想删除在每次迭代结束时打印的所有内容。 I tried to use print (hello[:char], end="\r") but it didn't seem to do the job.我尝试使用 print (hello[:char], end="\r") 但它似乎没有完成这项工作。
(Stack overflow won't let me share the output, It's too long. The output I got was a character added in each iteration, but in a new printed line) (堆栈溢出不会让我分享 output,它太长了。我得到的 output 是在每次迭代中添加的一个字符,但是在一个新的打印行中)
Thanks a lot!非常感谢!
Try this:尝试这个:
for char in range(len(hello)):
print (hello[:char], end='\r')
time.sleep(0.05)
Instead of using raw r
, use special character \r
- called carriage return.不要使用原始r
,而是使用特殊字符\r
- 称为回车。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.