How do I get rid of the ' the program is still running are you sure you want to kill it' warning on python?

前提是你 提交于 2019-12-06 12:42:04

问题


print ('Password Request Initiative')

password = 'abcd'
user_input = input('Please Enter Password: ')

if user_input != password:
    print("Haha. Nope") 
    quit()

elif user_input == password:
            print ("User is now logged in...")
    enter code here

that's the code, but when I run it and type the wrong password it shows this warning:And I want it to run without this message so it just instantly closes


回答1:


To avoid the message when running from IDLE, do not use quit() or exit() in a program. They are not part of the language and are not intended for this use. They are (usually) added by the site package for interactive use only. In particular, they were added so that people could more easily exit the interactive interpreter when running in a terminal window -- without knowing the magic control code needed on a particular system -- and without closing the terminal window itself.

C:\Users\Terry>python
Python 3.5.1 ... [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> ^D
SyntaxError: invalid syntax
>>> ^Z
C:\Users\Terry>python

On Unix, ^D, End of File, exits, but on DOS and still on Windows, ^Z<Return> is used instead. Few beginners know this. Other interactive programs use quit and exit, so we added those as synonyms.

With IDLE, ^D in the shell closes the shell on all systems, but not editor windows. It is the same as clicking the close button on the title bar. At least on Windows, ^Q == quit() and closes everything.

To exit a program when not as the bottom of a file, use raise SystemExit or sys.exit().

As the expansion of the acronym says, IDLE is a development environment. It is a feature of IDLE that testing a program within IDLE does not kill IDLE itself, at least not without warning.



来源:https://stackoverflow.com/questions/38028151/how-do-i-get-rid-of-the-the-program-is-still-running-are-you-sure-you-want-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!