I have just started with Python. When I execute a python script file on Windows, the output window appears but instantaneously goes away. I need it to stay there so I can an
I had a similar problem. With Notepad++ I used to use the command : C:\Python27\python.exe "$(FULL_CURRENT_PATH)"
which closed the cmd window immediately after the code terminated.
Now I am using cmd /k c:\Python27\python.exe "$(FULL_CURRENT_PATH)"
which keeps the cmd window open.
To just keep the window open I agree with Anurag and this is what I did to keep my windows open for short little calculation type programs.
This would just show a cursor with no text:
raw_input()
This next example would give you a clear message that the program is done and not waiting on another input prompt within the program:
print('You have reached the end and the "raw_input()" function is keeping the window open')
raw_input()
Note!
(1) In python 3, there is no raw_input(), just input().
(2) Use single quotes to indicate a string; otherwise if you type doubles around anything, such as "raw_input()", it will think it is a function, variable, etc, and not text.
In this next example, I use double quotes and it won't work because it thinks there is a break in the quotes between "the" and "function" even though when you read it, your own mind can make perfect sense of it:
print("You have reached the end and the "input()" function is keeping the window open")
input()
Hopefully this helps others who might be starting out and still haven't figured out how the computer thinks yet. It can take a while. :o)
You can just write
input()
at the end of your code
therefore when you run you script it will wait for you to enter something
{ENTER for example}
I found the solution on my py3 enviroment at win10 is just run cmd or powershell as Administrator,and the output would stay at the same console window,any other type of user run python command would cause python to open a new console window.
you can combine the answers before: (for Notepad++ User)
press F5 to run current script and type in command:
cmd /k python -i "$(FULL_CURRENT_PATH)"
in this way you stay in interactive mode after executing your Notepad++ python script and you are able to play around with your variables and so on :)
You can open PowerShell and type "python". After Python has been imported, you can copy paste the source code from your favourite text-editor to run the code.
The window won't close.