发生错误时如何防止控制台脚本关闭?
我制作了一个python程序,我使用 auto-py-to-exe
包装到 .exe
中我无法阅读错误。
而且我不想做:
try:
#code
except:
#print something
我希望它打印出原始的python错误,而不是立即使其立即关闭。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种方法可以
使用 trackback 模块
示例使用 print_exc
使用记录
使用记录模块的模块在许多情况下可以使用一些CLI FLAG或ENV变量来启用更多的详细记录。您还可以将所有日志转移到以后可以解析的文件中。
简单的记录示例
There are multiple ways to do this
Using the traceback module
Example using print_exc
Using the logging module
Utilizing the logging module can be useful in many cases for example you can enable more verbose logging using some CLI flag or env variable. You can also dump all the logs into a file that can be parsed later.
Simple logging example