用于人性化异常界面的工具包。

prettyexc的Python项目详细描述


https://travis-ci.org/youknowone/prettyexc.svg?branch=master

prettyex提供了通用的异常表示,以使人们可以轻松地读取异常。

您可以从pypi安装软件包

$ pip install prettyexc

示例

前奏曲:
>>> from prettyexc import PrettyException
始终放置和获取参数::
>>> class SimpleException(PrettyException):
...     pass
...
>>> e = SimpleException('any', 'plain', 'args', code=200, description='OK')
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.SimpleException: "any","plain","args",code=200,description="OK"
SimpleException("any","plain","args",code=200,description="OK")
>>> print [e, e]
[<SimpleException("any","plain","args",code=200,description="OK")>, <SimpleException("any","plain","args",code=200,description="OK")>]
设置默认消息::
>>> class MessageException(PrettyException):
...     message = u'You should select a user'
...
>>> e = MessageException(user_id=10)
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.MessageException: You should select a user
>>> print [e, e]
[<MessageException(user_id=10)>, <MessageException(user_id=10)>]
设置消息格式化程序::
>>> class FormatException(PrettyException):
...     message_format = u'User {user_id} has no permission.'
...
>>> e = FormatException(user_id=10)
>>> raise e
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.FormatException: User 10 has no permission.
>>> print e.message
User 10 has no permission.
dt>修补现有异常::
>>> from prettyexc import patch
>>> class AnException(Exception): pass
...
>>> patch(AnException, PrettyException)
>>> raise AnException(status=404)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.AnException: status=404

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java搜索按钮不适用于我   java制作一个应用程序来打开您自己的文件扩展名   XMemcached中的java异步集   java无法在Android上使用HTML5 canvas touch   java是否可以用PHP为Restlet创建客户端?   java在主题中添加图标。AppCompat。光   java Safari错误,无法打开浏览器   java gson解析json值中commaseparatedvalue字符串中的项   java如何使用Quarkus在卡夫卡的同一主题中设置多个使用者   java组织。json。JSONException:在{main}()的第6个字符处的main后面应该是“:”   windowbuilder如何将Java文件导出到GATE developer   java这与安卓 studio ide问题有关,在更新我们的ide之后   java Android将活动加载到类中<?>对象   java如何在springdatajpa中使用DISTINCT、GROUP BY和ORDER BY?   使用jlink的java可复制构建