python 美化輸出信息的實(shí)例
更新時(shí)間:2018年10月15日 10:49:54 作者:曉東邪
今天小編就為大家分享一篇python 美化輸出信息的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
如下所示:
# -*- coding: utf-8 -*- # @Author: xiaodong # @Date: just hide # @Last Modified by: xiaodong # @Last Modified time: just hide # try: # from colorama import Fore, Style # except ImportError: # class Temp: # def __getattr__(self, x): # return '' # Fore = Style = Temp() STYLE = { 'fore': { 'black': 30, 'red': 31, 'green': 32, 'yellow': 33, 'blue': 34, 'purple': 35, 'cyan': 36, 'white': 37, }, 'back': { 'black': 40, 'red': 41, 'green': 42, 'yellow': 43, 'blue': 44, 'purple': 45, 'cyan': 46, 'white': 47, }, 'mode': { 'bold': 1, 'underline': 4, 'blink': 5, 'invert': 7, }, 'default': { 'end': 0, } } def use_style(string, mode='', fore='', back=''): mode = '%s' % STYLE['mode'][mode] if mode in STYLE['mode'] else '' fore = '%s' % STYLE['fore'][fore] if fore in STYLE['fore'] else '' back = '%s' % STYLE['back'][back] if back in STYLE['back'] else '' style = ';'.join([s for s in [mode, fore, back] if s]) style = '\033[%sm' % style if style else '' end = '\033[%sm' % STYLE['default']['end'] if style else '' return '%s%s%s' % (style, string, end) def gentle_show(seq, *, column=4, fontdict=None): if fontdict is None: line_color = 'red' font_color = 'blue' elif isinstance(fontdict, dict): line_color = fontdict.get('line_color', 'red') font_color = fontdict.get('font_color', 'green') seq = list(map(str, seq)) max_len = len(max(seq, key=len)) for index, ele in enumerate(seq): if index % column == 0: print(use_style('-' * max_len * column + '-' * (column - 1), fore=line_color)) print(use_style(ele.center(max_len, ' '), mode='bold', fore=font_color), end='|') else: if (index - column + 1) % column == 0: print(use_style(ele.center(max_len, ' '), mode='bold', fore=font_color)) else: print(use_style(ele.center(max_len, ' '), mode='bold', fore=font_color), end='|') print('\n') if __name__ == "__main__": gentle_show(dir([]), column=6, fontdict={'line_color': 'red', 'font_color': 'green'}) gentle_show(range(10))
以上這篇python 美化輸出信息的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
opencv3/python 鼠標(biāo)響應(yīng)操作詳解
今天小編就為大家分享一篇opencv3/python 鼠標(biāo)響應(yīng)操作詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12pandas 實(shí)現(xiàn)某一列分組,其他列合并成list
這篇文章主要介紹了pandas 實(shí)現(xiàn)某一列分組,其他列合并成list的案例。具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2021-03-03Python操控Chrome瀏覽器進(jìn)行網(wǎng)頁(yè)操作
這篇文章將為您展示如何通過Python控制瀏覽器實(shí)現(xiàn)網(wǎng)頁(yè)的打開、頁(yè)面的切換和關(guān)閉的基本操作,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2023-06-06Python實(shí)現(xiàn)多任務(wù)進(jìn)程示例
大家好,本篇文章主要講的是Python實(shí)現(xiàn)多任務(wù)進(jìn)程示例,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽2022-01-01Python使用matplotlib模塊繪制圖像并設(shè)置標(biāo)題與坐標(biāo)軸等信息示例
這篇文章主要介紹了Python使用matplotlib模塊繪制圖像并設(shè)置標(biāo)題與坐標(biāo)軸等信息,結(jié)合實(shí)例形式分析了Python中matplotlib模塊進(jìn)行坐標(biāo)系圖形繪制的相關(guān)操作技巧,需要的朋友可以參考下2018-05-05Python人工智能之路 jieba gensim 最好別分家之最簡(jiǎn)單的相似度實(shí)現(xiàn)
這篇文章主要介紹了Python人工智能之路 jieba gensim 最好別分家之最簡(jiǎn)單的相似度實(shí)現(xiàn) ,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08