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

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第三方库


热门话题
Android中Twitter共享的java xAuth身份验证?   带有@XmlAnyAttribute和方法的java Bug?(使用JAXB-RI)   安卓 ArrayAdapter导致java。lang.NullPointerException   java如何使用JExel从现有excel文件中删除工作表   java树映射随机停止正确返回值   使用switch和scanner类java使用用户选择   java JCalendar多天选择   Java文件zip正在创建损坏的文件   Ajax调用中的java未定义错误   java处理JSON更改信息的最佳方法   java JNI不适用于AppKit线程   java在运行时为JTable的特定行设置背景色   java如何在for循环中添加按钮?   java在getclass()方法之后强制转换对象