问题描述
我想知道是否可以删除您在 Python 中打印的项目——不是从 Python GUI,而是从命令提示符.例如
I was wondering if it was possible to remove items you have printed in Python - not from the Python GUI, but from the command prompt.e.g.
a = 0
for x in range (0,3):
a = a + 1
b = ("Loading" + "." * a)
print (a)
所以它打印
>>>Loading
>>>Loading.
>>>Loading..
>>>Loading...
但是,我的问题是我希望这一切都在一行上,因此当其他事情出现时它会自行删除.因此,不是打印 "Loading", "Loading.", "Loading...
我希望它打印 "Loading."
,然后它会删除线上的内容并用 "Loading.."
替换它,然后删除 "Loading.."
并用 "Loading..." 替换它(在同一行)
.这有点难以描述.
But, my problem is I want this all on one line, and for it it remove it self when something else comes along. So instead of printing "Loading", "Loading.", "Loading...
I want it to print "Loading."
, then it removes what is on the line and replaces it with "Loading.."
and then removes "Loading.."
and replaces it (on the same line) with "Loading..."
. It's kind of hard to describe.
ps 我曾尝试使用退格字符,但它似乎不起作用 ("\b"
)
p.s I have tried to use the Backspace character but it doesn't seem to work ("\b"
)
谢谢
推荐答案
使用 CR 到行首即可.
Just use CR to go to beginning of the line.
import time
for x in range (0,5):
b = "Loading" + "." * x
print (b, end="\r")
time.sleep(1)
这篇关于移除和更换印刷品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!