前言
學習Linux
命令的朋友們肯定都學過或者聽說過figlet
這個有趣的命令,今天分享是Python
中實現這個命令的第三方庫:pyfiglet
。
pyfiglet
簡介
pyfiglet
是用Python寫的figlet命令的第三方庫,可以使用字元組成ASCII藝術圖片。
安裝
pip install pyfiglet
簡單使用
檢視可以使用的字型
在
Python
檔案中檢視>>> from pyfiglet import FigletFont >>> FigletFont().getFonts() ['clb6x10', 'nipples', 'computer', 'charact1', 'xtty', 'xcourb', 'xchartr', 'future_1', 'lcd', 'letters', 'fp2_____', 'rev', 'caus_in_', 'roman___', 'barbwire', 'threepoint', 'smkeyboard', 'couri', '1943____', 'heroboti', 'madrid', 'grand_pr', '3-d', 'radical_', 'atc_____', 'bubble_b', 'skate_ro', 'xsans', 'aquaplan', 'nvscript', 'brite', 'p_s_h_m_', 'tiles', 'xsbooki', 'pyramid', 'crawford', 'charact2', 'utopiai', 'future_2', 'shadow', 'italics_', 'asslt__m', 'new_asci', 'future_3', 'c2______', 'characte', 'charact3', 'sans', 'xsansbi', 'com_sen_', 'bulbhead', 'clr5x8', 'mshebrew210', 'doh', 'script__', 'platoon2', 'nancyj-fancy', 'mike', 'odel_lak', 'sansb', 'b_m__200', 'dwhistled', 'slide', 'future_7', 'joust___', '5x8', 't__of_ap', 'smscript', 'xbritebi', 'convoy__', 'alligator', 'graceful', 'gothic__', 'starwars', 'cli8x8', 'future_6', 'charact6', 'super_te', 'zig_zag_', 'xsansi', 'relief2', 'atc_gran', 'basic', 'vortron_', 'sm______', 'tecrvs__', 'pawn_ins', 'clb8x10', 'colossal', 'decimal', 'britei', 'unarmed_', 'funky_dr', 'jerusalem', 'fbr_stri', 'charact4', 'future_4', 'small', 'dcs_bfmo', 'future_5', 'britebi', 'charact5', 'courbi', 'morse', 'fender', 'clr7x8', 'notie_ca', '6x10', 'usaflag', 'hollywood', 'skateord', 'poison', 'pepper', 'rot13', 'coil_cop', 'master_o', 'puffy', 'raw_recu', 'times', 'eftitalic', 'stencil1', 'a_zooloo', 'catwalk', 'cour', 'isometric1', 'chunky', 'xcour', 'xbriteb', 'inc_raw_', 'yie-ar__', 'eftifont', 'tsalagi', 'block', 'rainbow_', 'mirror', 'avatar', 'defleppard', 'clr5x10', 'ok_beer_', 'stealth_', 'runyc', 'thick', 'univers', 'isometric3', 'top_duck', 'stencil2', 'utopiabi', 'alphabet', 'assalt_m', 'isometric2', 'banner3-D', 'ugalympi', 'char3___', 'script', 'tty', 'fair_mea', 'ti_pan__', 'ripper!_', 'war_of_w', '6x9', 'slscript', 'asc_____', 'fbr12___', 'twopoint', 'kgames_i', 'cosmike', 'deep_str', 'tsm_____', '4x4_offr', 'house_of', 'mnemonic', 'rok_____', 'clr7x10', 'nancyj-underlined', 'xhelvbi', '5lineoblique', 'tav1____', 'greek', 'eftiwater', '64f1____', 'subteran', 'sbookb', 'eftirobot', 'eftipiti', 'tombstone', 'modern__', 'kban', 'italic', 'clr6x8', 'smshadow', 'char1___', 'whimsy', 'cursive', 'hyper___', 'heavy_me', 'binary', 'xsbook', 'fbr_tilt', 'street_s', 'mini', 'xhelv', 'xhelvi', 'helv', 'helvb', 'isometric4', 'sblood', 'road_rai', 'ticks', 'fireing_', 'tsn_base', 'spc_demo', 'nancyj', 'rad_____', 'diamond', 'sketch_s', 'eftiwall', 'straight', 'sbookbi', 'xchartri', 'stellar', 'bubble__', 'pacos_pe', 'wavy', 'rci_____', 'beer_pub', 'invita', 'slant', 'bubble', 'npn_____', 'taxi____', 'marquee', 'twin_cob', 'clr6x6', 'rastan__', 'eftichess', 'contrast', 'cricket', 'trek', 'gothic', 'ascii___', 'goofy', 'speed', 'calgphy2', 'clr8x8', 'krak_out', 'z-pilot_', 'phonix__', 'cybersmall', 'banner3', 'zone7___', 'pebbles', 'platoon_', 'ebbs_1__', 'coinstak', 'green_be', 'letterw3', 'digital', 'demo_1__', 'fourtops', 'gauntlet', 'moscow', 'xbritei', 'xtimes', 'yie_ar_k', 'maxfour', 'f15_____', 'clr4x6', 'fraktur', 'hypa_bal', 'hills___', 'e__fist_', 'char4___', 'term', 'usa_pq__', 'chartri', 'katakana', 'ticksslant', 'xsbookbi', 'rockbox_', 'xcourbi', 'caligraphy', 'fbr2____', 'relief', 'chartr', 'jazmine', 'sbook', 'dotmatrix', 'nfi1____', 'mayhem_d', 'banner4', 'home_pak', 'doom', 'helvi', 'linux', 'tengwar', 'battlesh', 'xhelvb', 'lexible_', 'rowancap', 'peaks', 'mig_ally', 'ivrit', 'rad_phan', 'ghost_bo', 'acrobatic', 'contessa', 'battle_s', 'eca_____', 'ntgreek', 'smtengwar', 'flyn_sh', 'cyberlarge', 'larry3d', 'rounded', 'devilish', 'short', 'faces_of', 'type_set', 'hex', 'usa_____', 'tanja', 'r2-d2___', 'sbooki', 'big', 'rectangles', 'fp1_____', 'sansbi', 'c_consen', 'epic', 'pawp', 'utopia', 'p_skateb', 'c_ascii_', 'arrows', 'shimrod', 'char2___', 'xbrite', 'helvbi', 'smisome1', 'lockergnome', 'drpepper', 'magic_ma', 'graffiti', 'future_8', 'ebbs_2__', '5x7', 'tec_7000', 'star_war', 'letter_w', 'skateroc', 'fbr1____', 'gradient', 'utopiab', 'ts1_____', 'xsbookb', 'clr8x10', 'charset_', 'timesofl', 'high_noo', 'clr5x6', 'stop', 'xttyb', 'tomahawk', 'broadway', 'o8', 'tinker-toy', 'courb', 'etcrvs__', 'c1______', 'stacey', 'alligator2', 'demo_2__', 'triad_st', 'octal', 'lean', 'd_dragon', 'bell', 'ucf_fan_', 'xcouri', 'lazy_jon', 'rozzo', 'demo_m__', 'ttyb', 'fairligh', 'hades___', 'fuzzy', 'os2', 'smslant', 'rampage_', 'tubular', 'finalass', 'tec1____', 'ogre', 'stampatello', 'pod_____', 'rally_sp', 'clb8x8', 'outrun__', 'weird', 'kik_star', 'serifcap', 'briteb', 'mcg_____', 'standard', 'trashman', 'thin', 'xsansb', 'cybermedium', 'space_op', 'cosmic', 'fantasy_', 'double', 'advenger', 'druid___', 'sansi', 'rally_s2', 'mad_nurs', 'clr6x10', '3x5', 'bigchief', 'baz__bil', 'roman', 'runic', 'panther_', 'banner']
- 在終端中檢視
pyfiglet -l 或 pyfiglet --list_fonts
選一個喜歡的字型來輸出藝術字吧
>>> from pyfiglet import Figlet >>> f = Figlet(font="xtty") >>> f.renderText('Life is short, I use Python!') ' \n # ### # # \n# # # # ### \n# ### #### ## ### ### ### # # ## # ## #### # \n# # # # # # # # ## # # # ## # # # \n# # # #### # ## ## # # # # # # # \n# # # # # ## ## # # # # # # # \n# # # # # # # # # # # # # # # \n#### # # ### # ### ### # # ## # ## # ### \n # \n # \n \n # \n ### # # \n# # ### ## # # # # #### # # ## # # \n# # # # # # # # # # ## # # # ## # \n# # ## #### ### # # # # # # # # # \n# # ## # # ## # # # # # # # \n# ## # # # ## # # # # # # # \n # # ### ### # # ## # # ## # # \n # \n # \n'
這裡由於不能換行看的不是很清楚我們可以在
pycharm
中執行檢視上面由於太長了到了第二行,我們也可以指定寬度
from pyfiglet import Figlet f = Figlet(width=2000) print(f.renderText("Life is short, I use Python!"))
作用
寫程式碼也可以是有趣的,可以通過這個庫實現一些有趣的展示效果!
尾巴
Python
中還有很多第三方庫是Linux
命令的Python
版本,大家還知道那些,歡迎留言討論呀~
本作品採用《CC 協議》,轉載必須註明作者和本文連結