首页 > 解决方案 > 如何清除打印的文本?

问题描述

我在 python 3.8 中清除文本时遇到问题。我看过类似的答案,但他们并没有帮助我解决我遇到的问题,因为这些答案提供的解决方案对我不起作用。这是代码行:

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')

我想要做的是每次用户输入响应时响应将被清除并且它将是空白而不是像这样出现:

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 

我怎样才能解决这个问题?如果有帮助,我目前正在使用 python 3.8。

标签: pythonpython-3.xmacosprintingconsole

解决方案


按照https://stackoverflow.com/a/518007/1244045中的说明尝试此操作

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

'cls' 用于 Windows。


推荐阅读