So I just started learning Python and just now set up my Notepad++ to run it via cmd prompt. Is there a simple way to stop my cmd prompt from auto-exiting when I run a simple program? Do I need to ask for input every time or something or is there an easier way?
I tried raw_input('Press Enter to exit')
but no luck.
Here's the program my introduction to python book started me with http://pastebin.com/ZVJrUzZZ
If it makes any difference I'm running it straight to python.exe in python version 3.2
What I personally like to do is have the Python script just run to completion without asking for input, then write a batch file (Windows) or shell script (Linux/UNIX) to do the "press any key" thing. That way when I run the script from the command line it doesn't needlessly prompt me for input.
You could write a batch file like this:
python.exe %*
pause
Save it as pypause.bat
and tell Notepad++ to run your Python scripts via this batch file instead of through python.exe
.
You have the right idea. You would need to put something like raw_input()
somewhere before the script exits.
If this is python 3, use input
instead of raw_input
:
if __name__ == '__main__':
print(approximate_size(1000000000000, False))
print (approximate_size(1000000000000))
input('Press Enter to exit')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.