Python中的清除命令不仅在PyCharm中

时间:2018-02-09 16:01:21

标签: python pycharm clear

编辑:我不仅在PyCharm中寻找解决方案,而且一般情况下。 在这里,我在IDLE中运行代码并且仍然是相同的 enter image description here

我一直在网上搜索,但找不到合适的答案。我很确定这应该有一个非常简单的解决方案,但我可以搞清楚。

我有以下代码:

import calendar
import datetime
import os
now = datetime.datetime.now()
cal = calendar.calendar
while True:
    usr = input("Type: Today, Time, add event or remove event ")
    if usr.lower() == str("today"):
            print(now.strftime("%d-%m-%Y"))
            input("Press <Enter> to continue")
            os.system('cls' if os.name == 'nt' else 'clear')
    if usr.lower() == str("time"):
            print(now.strftime("%H:%M"))
            input("Press <Enter> to continue")
            os.system('cls' if os.name == 'nt' else 'clear')

我想要发生的是,在用户按下Enter后,程序将清除并返回到开头。

使用时:os.system('cls' if os.name == 'nt' else 'clear') 我得到enter image description here

当我不使用它时,程序会像这样保持堆叠输出: enter image description here

0 个答案:

没有答案