How to stop a run in Python? [duplicate]

1

I'm starting to program in Python and would like to know how do I stop running the program?

In language C for example, there is the equivalent command system("pause") . If I open the IDLE, more specifically the Python shell the program at the end of the window does not close. However, if I use the Python executable that is similar to CMD the program ends up closing when finished. What do I do to resolve this problem?

    
asked by anonymous 08.04.2017 / 18:18

2 answers

5

Use the "input" function - it waits until the user type enter (he can enter more text before pressing enter, but if you do not do anything with that text, it's indifferent):

input("Pressione <enter> para continuar")
The os.system("pause") runs another whole program - and means that the "Pause" program must exist on your operating system, and it is something Windows only: your Python (or C) program that would work on Linux, Mac , Android, becomes "windows only" just because of it. But above all, using 'system ("pause"), even in C, is equivalent in programming, calling a winch to take your car somewhere, with you inside, why the car is running out of gas rather than fueling.

Since the "input" function is internal to Python, you do not even need to import any module - and it depends only on the interaction of the Python runtime itself with the program's default input. (In C the correct would be to use the fgets function.)

    
09.04.2017 / 06:39
1

Try this, it will wait for you to type a key to continue

import os  
os.system("pause")
    
08.04.2017 / 18:33