Jump to content

Delete Last Line In Console Python 3

Spoiled_Kitten

Hi all!

I wish to share the discovery i made for deleting the last line in the console on python 3, I hope this can help someone, any questions please redirect to me,

Thanks,

Blake

 

 

code:

import os 
import sys
import time


#last line deletion
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')
    
    
###DEMO###
print("this line will delete in 5 seconds")
time.sleep(5)
delete_last_line()
 

 

The link to the github with the code and more is :

https://github.com/Blake-McCullough/LastLinePython3Delete/tree/main

 

Attached is also the file for deleting the last line if u wish to just download it.

Last line python 3 delete.py

Edited by Spoiled_Kitten
adding text code for others to see instead of visiting link or opening file.

Blake has arrived!!

Just your local tech geek!

Love to help!

Link to comment
Share on other sites

Link to post
Share on other sites

Why not just post the code in the forum rather than linking and posting random files

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

22 hours ago, vorticalbox said:

Why not just post the code in the forum rather than linking and posting random files

cause it changes quotations and stuff, ill try though.

Blake has arrived!!

Just your local tech geek!

Love to help!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×