Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何清除打印文本?_Python_Python 3.x_Macos_Printing_Console - Fatal编程技术网

Python 如何清除打印文本?

Python 如何清除打印文本?,python,python-3.x,macos,printing,console,Python,Python 3.x,Macos,Printing,Console,在python 3.8中清除文本时遇到问题。我看过类似的答案,但它们并没有帮助我解决问题,因为这些答案提供的解决方案对我不起作用。以下是代码行: def userInstructions(userInput): if userInput == "help" or userInput == "Help": help() elif userInput == "list" or userInput == "List": words() elif

在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')
我希望这样做的是,每当用户输入响应时,响应将被清除,并且将为空,而不是像这样显示:


键入您的命令或任何拉丁语单词以进行复习或学习。
输入您的回复:您好
输入您的命令或任何拉丁语单词进行复习或学习。
输入您的回答:帮助

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

脚本以基于操作系统清除屏幕

from os import name, system

# windows
if name == 'nt':
    system('cls')
# linux
else:
    system('clear')
如中所述尝试此方法


“cls”用于windows。

这是在什么操作系统中运行的?这是我第一次使用操作系统,所以我不知道,但我正在python 3.8中使用它@gdanton如果是windows,则必须使用“cls”@gdanton我使用的是MacOsThe
os.system('clear')
,代码中的
永远不会执行,因为
在退出函数之前返回输入('\enter your response:')
键入命令或任何拉丁单词以查看或学习。输入你的回复:他输入你的命令或任何拉丁单词来复习或学习。输入您的响应:帮助键入您的命令或任何拉丁语单词以进行查看或学习。命令列表帮助=显示命令列表=所有拉丁语I词汇列表教程=深入教程退出=退出主程序到退出学分,然后退出应用程序输入您的响应:退出
仍然是结果我希望避免它只是将自己放在另一行HMM。。维尔德。Python是否安装在MacOS中,并且您正在从终端运行程序?好的,它应该可以工作。如果你想从界面上做,唯一的方法似乎是通过打印新行字符来伪造它——不用担心。很高兴它成功了!总是给你的答案添加解释。
clear = lambda: os.system('clear')
clear()