Can't See The Output


#1

When I open a python file, the console opens and closes. I cannot see the output.
What should I add in my code so that the console remains running and I see the output?
I have saved the file as python.py


#2

assumption: windows as OS

open the command prompt (start key + r, type: cmd), and run the file: python python.py

or python3 python.py

this varies. Make sure you are in the right directory

You can also add sleep(5) to end of your script, you might need to import this (from time import sleep)


#3

Isn't there any way where the console closes after pressing Enter key or such?


#4

you could simply prompt for input and do nothing with it:

#python2 
raw_input("press any key to exit")
#python3
input("press any key to exit")

but shouldn't you also want to learn to run scripts from command line?


#5

Ok. That input("Press any key to continue") works.
Now when I try to run that python file from cmd it gives me the following error:

'python' is not recognized as an internal or external command,
operable program or batch file.

I created file on desktop and I am in the same directory. I tried both of these commands. The file name is same as I stated here.


#6

did you add python to your path during installation? Such issues are really difficult to trouble shoot for me remotely on a forum


#7

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.