On previous computers, when I would try to exit a Python script on the Windows command prompt, all you need to do is press ctrl+c.
But when I do that on my computer it tells me "KeyboardInterrupt":
C:\Windows\System32 >python Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 07:18:10) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> [I press ctrl+c] KeyboardInterrupt >>>
So how do I fix this so I can exit the Python script?
Thanks.
Edit:
ctrl+z works, but I need to enter it as code. Was hoping for a quick and easy way to just exit the script, but oh well.
To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program from running. It is the most reliable, cross-platform way of stopping code execution.
It indeed depends on the OS, and probably on the version of Python you are using.
As you mentioned, ctrl+C does not work on your Windows 10 with Python 3.6, but it does work on my Windows 10 with Python 3.4. Therefore, you really need to try and see what works for you.
Try the following commands, and keep the one that works:
In addition, the following should work with any terminal:
exit()
then Return quit()
then Return Trivia: if you type quit
and hit Return, the console tells you, at least for Python 3.4:
Use quit() or Ctrl-Z plus Return to exit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With