import sys
import time
def delete_last_line():
"Use this function to delete the last line in the STDOUT"
#cursor up one line
sys.stdout.write('\x1b[1A')
#delete last line
sys.stdout.write('\x1b[2K')
########## FOR DEMO ################
if __name__ == "__main__":
print("hello")
print("this line will be delete after 2 seconds")
time.sleep(2)
delete_last_line()
####################################
好吧,我有一个临时办法:
我想这就是你想做的:
这可以像使用下面的代码一样完成
或者在unix(mac和linux)上
os.system('clear')
。如果您也不希望向上滚动,则可以执行以下操作:os.system("printf '\033c'")
也应该去掉向后滚动。对所有系统都有效的东西:相关问题 更多 >
编程相关推荐