如何使python在错误后不关闭自我,python异常
我已经在Python中制作了一个程序,它使用自动py-to-exe转换为.exe,并且我想知道如何停止。Exe在错误后停止自我关闭(python exceptions)。光线,您无法阅读错误。
有人知道如何使它不关闭自己吗?
如果例外发生在PIP库中,请使用输入
不起作用
I have made an program in python that i converted into .exe using auto-py-to-exe and im wondering how to stop .exe stop closing it self after an error (python exception) the .exe closes it self in the speed of light and you cant read the error.
Does someone knows how to make it not close it self?
using input doesnt work if the exception happens in a pip library
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用基于试验的系统(您必须适当地构建以捕获代码的每个例外),并且要打印异常,您可以使用模块追溯这样:
或者您可以使用更简单的表格,例如:
只能打印出来错误类(例如找不到文件)。
我还应该指出,
终于存在
关键字,目的是执行代码是否出现,是否出现:您可以在此处执行的某些内容是记录程序使用
print的 所有内容(status_of_program,file = open('log.txt','a'))
这很有用,可以准确查看程序崩溃的时间,并且通常可以逐步查看程序中的程序。
但是,您应该做的一件事是在.py形式的情况下正确测试程序,如果起作用,您可能会假设错误来自实际的出口方法,并咨询文档或尝试导出更简单的程序以捕获差异(因此,错误)。
我建议咨询:
https://docs.python.org/3/library/library/lebibrary/exceptions.html
学习错误类型和Try-Excect构造。
如果输入()不起作用,请尝试使用
sys.stdout()
。You can use a try-except based system (that you have to build suitably to catch every exception of your code) and to print the exception you can use the module traceback like so:
or you could use a simpler form like:
that only prints the error class (like file not found).
I should also point out that the
finally
keyword exists with the purpose of executing code either if an exception arose or not:Something you could do on top of that is logging everything your program does with
print(status_of_program, file=open('log.txt','a'))
this is useful to see exactly at what point the program has crashed and in general to see the program in action step by step.
But a thing you should do is properly test the program while in .py form and if it works you could possibly assume the error comes from the actual exportation method and consult the documentation or try exporting simpler programs to catch the difference (and so the error).
i'd suggest to consult:
https://docs.python.org/3/library/exceptions.html
to learn the error types and the try-except construct.
If input() doesn't work try using
sys.stdout()
.我认为这是一个控制台应用。如果是GUI应用程序,则可以使用类似的方法,但是细节会有所不同。
我使用的方法是将
sys.excepthook
设置为打印异常的您自己的功能,然后等待输入。您可以调用现有的异常挂钩实际进行打印。I gather that this is a console app. If it's a GUI app, you can use a similar approach but the details will be different.
The approach I'd use is to set
sys.excepthook
to be your own function that prints the exception, then waits for input. You can call the existing exception hook to actually do the printing.