cowsay-讓你的python腳本也有大佬內(nèi)味

以前經(jīng)常看到互聯(lián)網(wǎng)大佬的Linux shell腳本啟動的時候顯示一副炫酷的字符畫面,逼格瞬間提升一個檔次,按說字符拼畫也不是什么難事,只要有時間、有耐心(然鵝大部分人這兩樣都沒有)。

網(wǎng)上流傳著一個很老的庫cawsay牛說。cowsay是一個生成ASCII圖片的程序,顯示一頭牛的消息。它也可以使用預(yù)先制作的圖像,以生成其他動物的圖片,如Linux的吉祥物企鵝。由于它是用Perl編寫的,它也適用于其他系統(tǒng),如微軟的Windows。

cawsay的風(fēng)格看起來是醬嬸兒的

$ fortune | cowsay
 ________________________________________
/ You have Egyptian flu: you're going to \
\ be a mummy.                            /
 ----------------------------------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

這里要安利的是python的cawsay版本,代碼在這里:
https://github.com/jeffbuttars/cowpy
使用很簡單,一鍵引入python程序,執(zhí)行即可,效果與Linux下的cawsay一樣樣的

安裝

pip install cowpy

使用

#!/usr/bin/env python
# encoding: utf-8

from cowpy import cow

# Create a Cow
cheese = cow.Moose()

# Get a cowsay message by milking the cow
msg = cheese.milk("My witty mesage")

# do something with the message
print(msg)

# Create a Cow with a thought bubble
cheese = cow.Moose(thoughts=True)
msg = cheese.milk("My witty mesage, with thought")
print(msg)

# Create a Cow with a tongue
cheese = cow.Moose(tongue=True)
msg = cheese.milk("My witty mesage, with tongue")
print(msg)

# Create a Cow with dead eyes
cheese = cow.Moose(eyes='dead')
msg = cheese.milk("my witty mesage, i'm dead")
print(msg)

# Get a cow by name
cow_cls = cow.get_cow('moose')
cheese = cow_cls()
msg = cheese.milk("Cow by name is moose")
print(msg)

# Create a Cow with a thought bubble, a tongue, and dead eyes
cheese = cow.Moose(thoughts=True, tongue=True, eyes='dead')
msg = cheese.milk("My witty mesage with several attributes")
print(msg)

這個函數(shù)可以隨機抽一個風(fēng)格的牛生成圖像:

# Create a random cow with a message
msg = cow.milk_random_cow("A random message for fun")
print(msg)

這個方法可以列舉所有備選圖像:

# all the eye options
eye_options = cow.eye_options()
print(eye_options)

# all the cowacter options
cow_options = cow.cow_options()
print(cow_options)

也可以引入fortune的語料庫隨機抽文字給cawsay,如此簡單兩步就可以讓你的python腳本瞬間擁有大佬內(nèi)味兒了。

   __________________________________________________________________
/ Do not argue with an idiot.                                      \
\ He will drag you down to his level and beat you with experience. /
 ------------------------------------------------------------------
  o
     o
                  _ _
       | \__/|  .~    ~.
       /$$ `./      .'
      {o__,   \    {
        / .  . )    \
        `-` '-' \    }
       .(   _(   )_.'
      '---.~_ _ _|
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 關(guān)系數(shù)據(jù)庫入門 關(guān)系數(shù)據(jù)庫概述 數(shù)據(jù)持久化 - 將數(shù)據(jù)保存到能夠長久保存數(shù)據(jù)的存儲介質(zhì)中,在掉電的情況下數(shù)據(jù)也不會...
    d4d98020ef88閱讀 1,054評論 0 0
  • 一,Python介紹 1. python的出生與應(yīng)用 python的創(chuàng)始人為吉多·范羅蘇姆(Guido van R...
    曹元_閱讀 235評論 0 8
  • 計算機的硬件組成 現(xiàn)代計算機的基本組成部分其實主要由三部分組成:CPU,內(nèi)存,主板。 你撰寫的程序,打開的任何PC...
    HikariCP閱讀 3,295評論 1 4
  • 之前Python就已經(jīng)學(xué)過了,F(xiàn)lask也玩的一溜一溜的。但是間隔時間有些長,所以就找個一個項目重新溫習(xí)一下,順便...
    d4d98020ef88閱讀 2,022評論 1 0
  • 我是黑夜里大雨紛飛的人啊 1 “又到一年六月,有人笑有人哭,有人歡樂有人憂愁,有人驚喜有人失落,有的覺得收獲滿滿有...
    陌忘宇閱讀 8,899評論 28 54

友情鏈接更多精彩內(nèi)容