Skip to content Skip to sidebar Skip to footer

Python Deleting Input Line

I would like to have an input loop in python 3 where the information which gets typed in gets deleted from terminal automatically (f.eks. after 3 seconds) I know the function with

Solution 1:

Ansi escape codes will not work the same on all terminals but this might suit your needs. The ‘\033’ is the escape character. The ‘[1A’ says go up one line and the ‘[K’ says erase to the end of this line.

prompt = 'Add the hidden word: '
inputStr = input(prompt).lower()
print ('\033[1A' + prompt + '\033[K')

Solution 2:

You want to clear the terminal with a function

# import onlysystemfrom os 
from os import system, name 

# import sleep toshow output forsometimeperiodfromtime import sleep 

# define our clear function 
def clear(): 

    # for windows 
    if name =='nt': 
        _ =system('cls') 

    # for mac and linux(here, os.name is'posix') 
    else: 
        _ =system('clear') 

Now you need to have a function that adds your word into a list then runs the clear function, then finally can pick a word at the end

Post a Comment for "Python Deleting Input Line"