[英]python remove the last line from the written file with file.write
[英]remove the last written line and replace it python
为了创建一个进度条,以显示当前的矿点
其背后的想法是先删除该行,然后再重写它,使其看起来像当前的流行。
我试图这样做:
import time
---some kind of loop---:
... downloading stuff ...
b = str((prhelp / 576)*100)
print(b + "%", end="\r")
time.sleep(1)
prhelp = prhelp + 1
但这只是不打印任何东西
我也想知道如何在点后仅3位打印数字12.345678
> 12.345
所以我的程序不会打印太久
这是因为在print
,您给参数end
是将添加到末尾的字符串。 默认情况下为\\n
。 您给了\\r
。 此字符的意思是删除当前行 。 这就是为什么它不打印任何东西的原因...
如果您希望它起作用,请替换为:
print(b + "%", end="\r")
通过:
print(b + "%")
我猜你想要的是:
import time
print('Hello', end='')
time.sleep(1)
print('\rworld!')
此代码将打印Hello
,等待1秒钟,然后按world!
替换Hello
world!
最后,我只需要做:
import time
b = str(round((prhelp / 576) * 100,3))
print('\r',end = "")
print(b + "%",end = "")
time.sleep(0.01)
prhelp = prhelp + 1
通过做
print('\r',end = "")
我要删除最后一行,并为下一个数字即时消息腾出地方。
谢谢所有的帮手
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.