I’m learning Python and I noticed something strange.
When I double-click my Python file (.py) on Windows to run it, the program seems to run twice.
Here is a simple example:
print("Program started")
name = input("Enter your name: ")
print("Hello,", name)
When I run the file by double-clicking it:
The console opens
Prints “Program started”
Immediately closes and reopens again, asking for input
Sometimes the console closes before I can read the output
But when I run the same code from VS Code or CMD, it runs normally.
My questions:
Why does double-clicking a .py file cause the console to open/close so quickly or run twice?
Is there a correct way to run Python scripts by double-clicking so they don’t auto-close?
Should beginners always use CMD/VS Code instead of double-clicking .py files?
I tried searching, but most answers are about loops or input errors, not about double-running on Windows.
Thanks!
print()statement, so the program is finished at at point, and the application window closes. Why did you expect it to wait?inputstatement rather than exit immediately.pauseafter the python run command. This way you can still run it normally in from cmd without having some randominput()at the end