![](/img/trans.png)
[英]how do i clear the output screen or terminal in python? os.system("clear") and os.system("cls") did not work. (In google collaboratory)
[英]How can I delete some output lines?(without using of os.system('cls'))
我想編輯輸出中最后幾行的一些(多於一行)。 但是我在它們之前有很多行,清除並重新打印所有這些行會減慢我的程序速度(我不能使用'\\r'
因為我要編輯的行不止一行)。
print("Lots of lines")
print("Lines to be edited\nLines to be edited")
您可以使用:
print ("\033[A \033[A")
它從輸出中清除一行。 您可以在下面看到其工作原理的示例:
print("Hello world\n xxx \n xxx")
print ("\033[A \033[A")
print ("\033[A \033[A")
輸出:
Hello world
我想清除包含xxx
兩條輸出行,所以我打印了兩次。
您可以使用它並制作一些 for 循環等。
請注意,在 Windows 上,您可能需要使用以下網址啟用 ANSI 支持http://www.windowsnetworking.com/kbase/windowstips/windows2000/usertips/miscellaneous/commandinterpreteransisupport.html
"\\033[A"
字符串被終端解釋為將光標向上移動一行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.