【问题标题】:Clearing the text from the python shell [duplicate]从python shell中清除文本[重复]
【发布时间】:2017-11-07 19:41:47
【问题描述】:

好的,所以我目前正在用 python 编写刽子手,我想知道我是否可以清除它在 python shell 中所说的内容,因为我不只是不想让这个人读到这个词。

import time
keyword = input(" Please enter the word you want the person to guess")
lives = int(input("How many lives would you like to have?"))
print ("There are ", len(keyword), "letters in the word")

time.sleep(2)

guess = input("please enter your guess")

我想删除 shell 中的所有文本。

【问题讨论】:

  • 给我们看代码.....为什么开头的字是可见的?
  • 您是在询问clearing the entire shell 还是只清除显示的特定文本?正如@depperm 提到的,请分享一些代码,或者更清楚/具体地说明您的要求。

标签: python


【解决方案1】:

如果您是 Windows 用户,请使用:

import os
os.system("cls")

然后是 Mac/linux :

import os
os.system("clear")

【讨论】:

    【解决方案2】:
    print("\n" * 100)
    

    除了向控制台发送垃圾邮件之外,没有其他方法可以做到这一点。

    【讨论】:

      【解决方案3】:

      试试这个:

      import subprocess
      import time
      
      tmp=subprocess.call('clear', shell=True) # 'cls' in windows
      keyword = input(" Please enter the word you want the person to guess")
      lives = int(input("How many lives would you like to have?"))
      print ("There are ", len(keyword), "letters in the word")
      
      time.sleep(2)
      

      将代码保存在 python 文件中。然后从 shell 中执行它。

      【讨论】:

        【解决方案4】:

        os.system("cls") 适用于 windows 或 os.system("clear") 适用于 mac/linux。

        然后将该行代码放在您希望程序删除外壳中所有文本的位置。

        【讨论】:

          猜你喜欢
          • 2017-06-13
          • 2013-07-01
          • 2012-08-21
          • 2016-08-27
          • 1970-01-01
          • 2015-07-06
          • 2020-08-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多