https://github.com/youknowone/prettyexc
Make your python exception human readable in easy way.
https://github.com/youknowone/prettyexc
exception python
Last synced: about 1 year ago
JSON representation
Make your python exception human readable in easy way.
- Host: GitHub
- URL: https://github.com/youknowone/prettyexc
- Owner: youknowone
- License: other
- Created: 2013-01-11T10:06:47.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2019-02-21T12:19:05.000Z (over 7 years ago)
- Last Synced: 2025-04-07T00:46:38.105Z (about 1 year ago)
- Topics: exception, python
- Language: Python
- Homepage: http://pypi.python.org/pypi/prettyexc
- Size: 26.4 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
Pretty-Exception for Python
~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. image:: https://travis-ci.org/youknowone/prettyexc.svg?branch=master
:target: https://travis-ci.org/youknowone/prettyexc
prettyexc provides common exception representation to make human-readable exception in easy way.
You can install the package from PyPI
$ pip install prettyexc
Example
-------
Prelude::
>>> from prettyexc import PrettyException
Put and get your arguments always::
>>> class SimpleException(PrettyException):
... pass
...
>>> e = SimpleException('any', 'plain', 'args', code=200, description='OK')
>>> raise e
Traceback (most recent call last):
File "", line 1, in
__main__.SimpleException: "any","plain","args",code=200,description="OK"
SimpleException("any","plain","args",code=200,description="OK")
>>> print [e, e]
[, ]
Set default message::
>>> class MessageException(PrettyException):
... message = u'You should select a user'
...
>>> e = MessageException(user_id=10)
>>> raise e
Traceback (most recent call last):
File "", line 1, in
__main__.MessageException: You should select a user
>>> print [e, e]
[, ]
Set message formatter::
>>> 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 "", line 1, in
__main__.FormatException: User 10 has no permission.
>>> print e.message
User 10 has no permission.
Patch existing exceptions::
>>> from prettyexc import patch
>>> class AnException(Exception): pass
...
>>> patch(AnException, PrettyException)
>>> raise AnException(status=404)
Traceback (most recent call last):
File "", line 1, in
__main__.AnException: status=404