Reputation: 1039
I'm a beginning programmer in Python and I have a strange problem with my computer. When I have a .py file on my computer (containing a script that works), and I double click on it to open, the following happens: the program opens (it's the black screen view), but it shuts itself down within a second, and the program isn't executed. However, when I right click and choose "edit with IDLE", everything works as normal.
I didn't have this problem from the beginning on, but then I installed some other versions of Python and I think that's the moment when scripts didn't want to open anymore.
Upvotes: 1
Views: 239
Reputation: 896
Austin is right, you made a console app, and once its finished(in microseconds), it closes itself.
Create a mainloop or use Austin's trick, to force app not to close itself.
Upvotes: 2
Reputation: 4633
but it shuts itself down within a second, and the program isn't executed.
Yes, the program is being executed. It is being executed so quickly that you don't have a chance to see what is happening.
Put raw_input()
at the end of your code so that the console window doesn't close instantly.
Upvotes: 2
Reputation: 3985
What is happening is that there has been an association with the py
extension and it probably is running your program, but it is closing too quickly for you to see any output. You can add a wait or just open a command prompt and run everything from there.
Another solution, and in my opinion the more ideal one, is to set the association of the py
extension to IDLE. This would solve your issue as the file will open by default in IDLE and from there you can run the Python script.
Changing File Associations In Windows 7
Upvotes: 7