Spice up those exceptions with cowexcept!
Project description
CowExcept
Spice up those exceptions with cowexcept!
______________________________________
< NameError: name 'baz' is not defined >
--------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Install
pip install cowexcept
Usage
All you have to do to get started is activate cowexcept
and then any
exceptions whenceforth will be in beautiful cowsay format:
>>> import cowexcept
>>> cowexcept.activate()
>>> 1/0
_____________________________________
/ Traceback (most recent call last): \
| File "...", line 1, in ... |
| 1 / 0 |
\ ZeroDivisionError: division by zero /
-------------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
The cowexcept.activate()
call is to avoid unused import flags from IDEs or
style checkers and avoiding any import-time side effects. If unused imports and
import-time side effects do not bother you, and you would prefer to avoid the
horrible extra line used to explicitly activate cowexcept
,
use import cowexcept.auto
instead and this will activate cowexcept
on
import.
To deactivate cowexcept
call cowexcept.deactivate()
and any exceptions will
be handled as before.
Using Your Own Cows
You can specify alternative cows to display using the set_cow
and set_cow_from_file
functions.
The set_cow
function takes the name of any cowfile included in
the python-cowsay package and sets the
cow to be displayed in exceptions.
>>> import cowexcept
>>> cowexcept.activate()
>>> cowexcept.set_cow("dragon-and-cow")
>>> 1 / 0
_____________________________________
/ Traceback (most recent call last): \
| File "...", line 1, in ... |
| 1 / 0 |
\ ZeroDivisionError: division by zero /
-------------------------------------
\ ^ /^
\ / \ // \
\ |\___/| / \// .\
\ /O O \__ / // | \ \ *----*
/ / \/_/ // | \ \ \ |
@___@` \/_ // | \ \ \/\ \
0/0/| \/_ // | \ \ \ \
0/0/0/0/| \/// | \ \ | |
0/0/0/0/0/_|_ / ( // | \ _\ | /
0/0/0/0/0/0/`/,_ _ _/ ) ; -. | _ _\.-~ / /
,-} _ *-.|.-~-. .~ ~
\ \__/ `/\ / ~-. _ .-~ /
\____(oo) *. } { /
( (--) .----~-.\ \-` .~
//__\\ \__ Ack! ///.----..< \ _ -~
// \\ ///-._ _ _ _ _ _ _{^ - - - - ~
You can also specify custom cows by passing in a cowfile or TextIO stream to
the set_cow_from_file
function:
>>> from io import StringIO
>>> import cowexcept
>>> cowexcept.set_cow_from_file(StringIO("""
... $the_cow = <<EOC;
... $thoughts
... $thoughts
... ___
... (o o)
... ( V )
... /--m-m-
... EOC
... """))
>>> cowexcept.activate()
>>> 1 / 0
_____________________________________
/ Traceback (most recent call last): \
| File "...", line 1, in ... |
| 1 / 0 |
\ ZeroDivisionError: division by zero /
-------------------------------------
\
\
___
(o o)
( V )
/--m-m-
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cowexcept-1.3.1.tar.gz
.
File metadata
- Download URL: cowexcept-1.3.1.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 897b6de11ef778d4aebff4bc6b15b5e2577037627879a19bf7facb72ceb8b3ce |
|
MD5 | 3176b9ab8f5f29632ab1fdeb43dde2b1 |
|
BLAKE2b-256 | 7122d7ade9feed2b94cdf7cc3aabdbf9d4f232b34cb28cc24a3506c5077a12b5 |
File details
Details for the file cowexcept-1.3.1-py3-none-any.whl
.
File metadata
- Download URL: cowexcept-1.3.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c9471f698f6751de9caeb96c36c09abf634998d0f69c8121c9bd443354fe7cd |
|
MD5 | c71202bf3f985f2dd2ad6beacec6c3bd |
|
BLAKE2b-256 | 9fefecb77ca43bd389fffc57423bf03870299716e138244891df9a7e9d1f1f5a |