I have just started with Python. When I execute a python script file on Windows, the output window appears but instantaneously goes away. I need it to stay there so I can analyze my output. How can I keep it open?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
On windows 10 insert at beggining this:
Strange, but it work for me!(Together with input() at the end, of course)
In python 2 you can do it with: raw_input()
In python 3 you can do it with: input()
Also, you can do it with the time.sleep(time)
cmd /k
is the typical way to open any console application (not only Python) with a console window that will remain after the application closes. The easiest way I can think to do that, is to press Win+R, typecmd /k
and then drag&drop the script you want to the Run dialog.A very belated answer, but I created a Windows Batch file called
pythonbat.bat
containing the following:and then specified
pythonbat.bat
as the default handler for.py
files.Now, when I double-click a
.py
file in File Explorer, it opens a new console window, runs the Python script and then pauses (remains open), until I press any key...No changes required to any Python scripts.
I can still open a console window and specify
python myscript.py
if I want to...(I just noticed @maurizio already posted this exact answer)
On Python 3
Will do the trick.
If you want to run your script from a desktop shortcut, right click your python file and select
Send to|Desktop (create shortcut)
. Then right click the shortcut and select Properties. On the Shortcut tab select the Target: text box and addcmd /k
in front of the path and click OK. The shortcut should now run your script without closing and you don't need theinput('Hit enter to close')
Note, if you have more than one version of python on your machine, add the name of the required python executable between cmd /k and the scipt path like this: