2017-10-10 84 views
-2

我正在編寫一個測試程序來測試python中的一些東西,我似乎無法找到一種方法來結束程序並關閉python窗口。 這是我的代碼:有沒有辦法使用python關閉python窗口?

yesorno = input('If you want to start the program, type yes, if not type 
no') 
def cls(): print('hello') 
cls() 

if yesorno == 'y': 
    del yesorno 

elif yesorno == 'n': 
    print("you chose wrongly.") 

任何幫助是非常讚賞。

+0

**進口SYS ** ** 進口時間**可以幫助您在這個 –

+0

您可以使用SYS .exit()終止程序。 –

回答

2

試試這個:

import sys 
sys.exit() 
+0

我試過了,我得到了這個錯誤:AttributeError:''對象在第4行沒有屬性'exit' –

0

我評論的解決方案,但因爲你對此有何評論回來,你得到所以這裏的錯誤是完整的解決方案:

首先你命名的任何一個您的文件sys與本地命名空間和內置命名空間衝突,因爲sys是內置命名空間,但是當您在IDE中使用相同名稱創建自己的文件時,python首先嚐試在Local >> Enclosed >> Global >> Built-in中查找,這被稱爲LEGB規則。

更改文件名到別的東西,然後嘗試,我註釋掉的代碼:

import sys 
sys.exit() 
相關問題