+ 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😲

12th Apr 2017, 9:30 AM
dailei
4 Respostas
+ 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
12th Apr 2017, 9:44 AM
Ruslan Ovcharenko
Ruslan Ovcharenko - avatar
+ 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?
12th Apr 2017, 9:49 AM
dailei
+ 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"
12th Apr 2017, 12:30 PM
Talha Waheed
Talha Waheed - avatar
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.
12th Apr 2017, 1:07 PM
dailei