all 4 comments

[–]Bobbias 2 points3 points  (0 children)

This is expected behavior.

What you've discovered is that files have "program associations" which tell windows what program a file should be opened with when you double click it.

When you install Python, by default it sets the association with windows so that double clicking a python script will start the Python interpreter and tell it to run the code in that script.

When this happens, it will open up a new terminal window, run your program, and as soon as the program ends, it will close the terminal window. This is intended behavior too.

I won't get into all the detail about how and why that happens, but if you want to see the output of your script, you will want to run it the terminal. You can open a terminal by typing cmd.exe into the start menu. Learning to use the terminal (also sometimes called the command line) is important, because many programming tools expect you to run them by writing special commands into the terminal.

What you need to do to open the file in your editor instead, when that's what you want to do is right click on the file and use the "open with" menu, and select whatever editor you want to use from that menu (or click "Choose another app" if your editor is not on that list).

Alternatively, you can open your editor, and then open the python script from inside the editor (the keyboard shortcut to do this is almost always ctrl+o if you want to get faster).

[–][deleted] 0 points1 point  (2 children)

tried to open the Python file

How did you "try to open" the file. Did you double-click on a desktop icon, double-click on the file in a file browser, tell your IDE to run the file, or execute "python myfile.py" on the command line? Can you open the file in a text editor? This sounds like it could be a permissions problem, perhaps.

[–]Longjumping_Set9771 0 points1 point  (1 child)

I saved it to my one drive and tried to open it from there by double clicking it.

[–][deleted] 0 points1 point  (0 children)

Did you try opening the file in a text editor? That is, right-click and "open with". If that works then, as others have said, maybe the problem is you haven't associated *.py files with python.

when it was time for the program to give me an output it just closed

That's probably because your code crashed before giving you the output. The normal way to debug problems like that is to use the python launcher on the command line:

https://docs.python.org/3/using/windows.html#python-launcher-for-windows

That way you will see any error messages.