0

I'm having trouble with clearing text in python 3.8. I've looked at similar answers but they didn't help me with the problem I'm having since the solutions those answers offered did not work for me. here's the line of code:

def userInstructions(userInput):
    if userInput == "help" or userInput == "Help":
        help()
    elif userInput == "list" or userInput == "List":
        words()
    elif userInput == "tutorial" or userInput == "Tutorial":
        tutorial()
    elif userInput == "salve":
        LatinRef.salve()

    return input('\nEnter your responce: ')
    os.system('clear')

What I want this to do is every time the user inputs a response that response would be cleared and it would be blank instead of appearing like this:

Type in your command or any Latin word to review or learn.

Enter your responce: hello
Type in your command or any Latin word to review or learn.

Enter your response: help 

how can I fix this? I'm currently using python 3.8 if that helps.

martineau
  • 119,623
  • 25
  • 170
  • 301

2 Answers2

1

Try this as mentioned in https://stackoverflow.com/a/518007/1244045

clear = lambda: os.system('clear')
clear()

'cls' for windows.

gdanton
  • 310
  • 2
  • 13
  • `Type in your command or any Latin word to review or learn. Enter your responce: he Type in your command or any Latin word to review or learn. Enter your responce: help Type in your command or any Latin word to review or learn. list of commands help = Display of commands list = list of all the Latin I vocabulary tutorial = in depth tutorial Quit = exits the main program to the exit credits and then exits the app Enter your responce: Quit` – Sergio Ley-Languren Dec 12 '19 at 04:52
  • still the result I want to avoid it just putting itself on another line – Sergio Ley-Languren Dec 12 '19 at 04:53
  • Hmm.. Wierd. Is the Python installed in MacOS and you are running the program from terminal? – gdanton Dec 12 '19 at 04:56
  • I'm running the program through python IDL but once I'm finished would turn it into a separate app. I got python3.8 from the python website – Sergio Ley-Languren Dec 12 '19 at 04:58
  • Ok, that might be problem. Can you try running from terminal? – gdanton Dec 12 '19 at 05:02
  • sure, it would take a while since this program I'm creating is using three files so it will take me some time. – Sergio Ley-Languren Dec 12 '19 at 05:04
  • 1
    Ok, it should work. If you want to do from interface the only way seems to be faking it by printing new line characters - https://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window – gdanton Dec 12 '19 at 05:06
  • I actually did something wrong when using your code. I saw a comment in this question and I realized that I've put it in the wrong area so now it works. Thank you and sorry if I wasted your time. – Sergio Ley-Languren Dec 12 '19 at 05:10
  • 1
    No worries. Glad it worked! – gdanton Dec 12 '19 at 05:17
0

Script to clear screen based on the os

from os import name, system

# windows
if name == 'nt':
    system('cls')
# linux
else:
    system('clear')
partha biswas
  • 204
  • 1
  • 7