发生Python错误后,请保持Windows控制台处于打开状态 [英] Keep Windows Console open after a Python Error

查看:71
本文介绍了发生Python错误后,请保持Windows控制台处于打开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的机器(winxp主页)上的文件关联使得可以使用python解释器直接打开python脚本。如果我双击python脚本,则控制台窗口将运行,并且一切正常-只要脚本中没有语法错误即可。

File associations on my machine (winxp home) are such that a python script is directly opened with the python interpreter. If I double click on a python script a console window runs and every thing is fine - as long as there is no syntax error in the script.

在这种情况下,控制台窗口会打开一会儿,但会立即关闭。太快了,无法读取错误消息。

In that case the console window opens up for a moment but it is closed immediately. Too fast to read the error message.

当然,可以通过手动输入 python来手动打开控制台窗口并执行脚本myscript.py ,但我确定有一个更方便的解决方案(即基于双击)。

Of course their would be the possibility to manually open a console window and to execute the script by typing python myscript.py but I am sure that there is a more convenient (i.e. "double click based") solution.

推荐答案

制作一个批处理文件:

C:\Python26\python.exe %1
IF %ERRORLEVEL% NEQ 0 PAUSE

使用它作为您的文件关联而不是直接使用python.exe。仅当python.exe返回错误时,才会导致执行PAUSE语句

Use that as your file association instead of python.exe directly. This will only cause the PAUSE statement to execute if python.exe returns an error

这篇关于发生Python错误后,请保持Windows控制台处于打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆