• Stars
    star
    139
  • Rank 257,101 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 2 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Spice up those exceptions with cowexcept!

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-

More Repositories

1

adventofcode

My solutions to the Advent of Code challenges
Python
23
star
2

cowsay

A rewrite of cowsay in python
Python
6
star
3

manim-ds

Python
6
star
4

pipe-utils

Python with pipes, utils, and pipe utils.
Python
5
star
5

list2csv

A simple package intended to help write iterables of objects to CSV files
Python
3
star
6

tinyerr

tiny errors that get straight to the point
Python
3
star
7

python-docusaurus-template

A no-nonsense markdown-only template with runnable and editable Python code blocks
JavaScript
3
star
8

tumblr-dot-com

A tumblr API client with support for polls
Python
2
star
9

pkl-nhi

NHI validator in Pkl
2
star
10

qChecker

qChecker is a simple package that inspects python code and is intended for checking that student-submitted code satisfies given constraints.
Python
2
star
11

qchecker

A library intended to identify semantically meaningful micro-antipatterns in student code
Python
2
star
12

python-nhi

Checks strings against the New Zealand Ministry of Health NHI Validation Routine
Python
2
star
13

python-fsa

A small project demonstrating both deterministic and nondeterministic finite state machines
Python
2
star
14

toodle

A small transpiler that converts human-readable text and TOML file formats representing Moodle questions to Moodle XML
Python
1
star
15

worble

A good-enough text-based clone of Wordle.
Python
1
star
16

pytubemusic

A cli that may or may not download music from a certain website
Python
1
star
17

trellocardsortparser

A simple set of scripts to parse and analyse card sorts performed on Trello.
Python
1
star
18

tonally

A little project to keep me busy while I learn Elm (and tones).
Elm
1
star
19

foobar-example

Example Code used for UoA's CS399 GitHub Workshop
Python
1
star
20

an-horse

JavaScript
1
star