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

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

cowexcept-1.3.2.tar.gz (7.1 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.3.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cowexcept-1.3.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cowexcept-1.3.2.tar.gz
Algorithm Hash digest
SHA256 81c5a08013224867534fe809447f9a95ac61e32a43114c5be7414da8dda7e3bb
MD5 89d046f7626693a99df474e427a07b13
BLAKE2b-256 66077a33bcdf84af519bf0cbc43e3782ac8898f6504537402fdcd37074b7c6ab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cowexcept-1.3.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cowexcept-1.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 152a84cb73d42f63b2b1527067902fc852e23cde20d29e5c545e7aa941b30eff
MD5 eaf3dc75d25a441dac81c48740d0386b
BLAKE2b-256 b0e381ef4212f00f6bcf6c89d9ef34d07d463ae29d5e22a3f44c0ac658042e50

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