+ 1
How to run a .py file and keep the result dialog open
I wrote a py file and saved on my desktop, I can double-click it to run this file. But the question is, the dialog(a black window like cmd.exe) appeared a little moment and closed immediately. 😩 How to keep the dialog open ,and I can close it whenever i want😲
4 Réponses
+ 3
try this:
from os import system
system('pause')
it using system command 'pause'
or:
from time import sleep
sleep(5)
it will stop your script for 5 seconds
+ 2
I'll try it,if the api system can be used here,does that mean any api for c can be used by this way in python?
+ 1
You should need to run your file from cmd Typein window+r button. Write cmd and press enter . Command promt will open. Now navigate to the directory in which file is located with cd command. And after reaching to directory simple typin python "filename" this will run the file as you want if it shows that command not found then you have to put the full path of python installation direction ie the command would be c:/Python27/python "filename"
0
I tried these two ways and they all worked well! Thank you both.
Actually, it's more convenient to import os and call system func, then the py file can be processed by double-click. I like this way.