If you've got a Python program and you want to make it wait, you can use a simple function like this one: time. sleep(x) where x is the number of seconds that you want your program to wait.
sleep() – Pause, Stop, Wait or Sleep your Python Code. Python's time module has a handy function called sleep(). Essentially, as the name implies, it pauses your Python program. The time.
Pause a Program in Python Using the os. system("pause") Method. The os. system("pause") method pauses the program's execution until the user does not press any key.
Use time. This will sleep for half of a second.
One way is to leave a raw_input()
at the end so the script waits for you to press Enter before it terminates.
Try os.system("pause")
— I used it and it worked for me.
Make sure to include import os
at the top of your script.
There's no need to wait for input before closing, just change your command like so:
cmd /K python <script>
The /K
switch will execute the command that follows, but leave the command interpreter window open, in contrast to /C
, which executes and then closes.
The best option: os.system('pause')
<-- this will actually display a message saying 'press any key to continue' whereas adding just raw_input('')
will print no message, just the cursor will be available.
not related to answer:
os.system("some cmd command")
is a really great command as the command can execute any batch file/cmd commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With