-1

I wrote a very simple Python program that just has a few print statements in it. When I run it from the IDE it runs fine. However, when I try to open up the program from my desktop (where I saved it) it opens runs and immediately closes.

How can I keep it open? Is there a statement or some function I need to add at the end or beginning?

3 Answers3

1

Try adding below line end of your code. It will wait until you press enter.

input("Press enter")

You can delete the text like below :

input("")
0

Assuming that you are using some kind of Windows OS, you can try to open command line window by hitting Ctrl+R and typing

cmd

after that you should be able to run your python script by typing

python c:/path/to/the/script.py
Kamil
  • 2,712
  • 32
  • 39
0

If you run it in a command shell instead of just double-clicking on the python file, the command shell will stay open, allowing you to see the output.

Brendan Abel
  • 35,343
  • 14
  • 88
  • 118