Skip to main content

Spice up those exceptions with cowexcept!

Project description

CowExcept

Repository PyPi License

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 |
                ||     ||

If no cow or cow file is specified, cows are chosen at random (from cowsay -l from the python-cowsay package). When activating cowexcept, a cow name can be provided to set the cow for all exceptions:

>>> import cowexcept
>>> cowexcept.activate("elephant-in-snake")
>>> 1 / 0
 _____________________________________
/ Traceback (most recent call last):  \
|   File "...", line 1, in ...        |
|     1 / 0                           |
|     ~~^~~                           |
\ ZeroDivisionError: division by zero /
 -------------------------------------
   \
    \              ....       
           ........    .      
          .            .      
         .             .      
.........              .......
..............................

To deactivate cowexcept call cowexcept.deactivate() and any exceptions will be handled with Python's default exception handler.

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

cowexcept-1.4.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cowexcept-1.4.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file cowexcept-1.4.0.tar.gz.

File metadata

  • Download URL: cowexcept-1.4.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for cowexcept-1.4.0.tar.gz
Algorithm Hash digest
SHA256 9cd913cf871563d0b257c194759fd540d001620f7f67c13d90c2277dc385136a
MD5 7fccb61a2981c6235ad120f3bbc7bf50
BLAKE2b-256 8804bb6aba6fceb4b66f9f4c20d6f5b24fd27478c64a21d7221fa92b7e561c39

See more details on using hashes here.

File details

Details for the file cowexcept-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: cowexcept-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for cowexcept-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85b00ed967f8a424c77b56d9efd0e8bd936e68656a749de58db123a6605a4c97
MD5 218ef487b0417bb3c80ad50570bca2c7
BLAKE2b-256 993e457a8ff27660b628a90bf6ee203a7fcbf802630eb7ddd3b9f64366c518ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page