2017-06-06 28 views
-1

好的,所以我现在正在编写python的hangman编码,并且想知道我是否可以清除python shell中的内容,因为我不只是不想让人读字。从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中的所有文本。

+0

向我们展示代码.....为什么这个词在开始时可见? – depperm

+1

您是否在询问[清除整个shell](https://stackoverflow.com/questions/517970/how-to-clear-the-interpreter-console)或仅清除显示的特定文本?正如@depperm提到的那样,请分享一些代码或者更清楚/具体地说明您要求的内容。 –

回答

1

如果你是一个Windows用户使用这样的:

import os 
os.system("cls") 

的Mac/Linux的那么:

import os 
os.system("clear") 
0

试试这个:

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执行它。

0
print("\n" * 100) 

没有其他方法可以做到这一点,只是垃圾邮件控制台。

0

os.system("cls") for windows或os.system("clear") for mac/linux。

然后把那行代码放在你希望程序删除shell中的所有文本的地方。