擅长:python、mysql、java
<p>我想这就是你想做的:</p>
<blockquote>
<p>take the cursor one line up and delete the line</p>
</blockquote>
<p>这可以像使用下面的代码一样完成</p>
<pre><code>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()
####################################
</code></pre>