国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python 美化輸出信息的實(shí)例

2020-01-04 14:21:38
字體:
供稿:網(wǎng)友

如下所示:

# -*- 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,美化,輸出信息

python,美化,輸出信息

python,美化,輸出信息

以上這篇python 美化輸出信息的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識閱讀請移步到python教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 义乌市| 汝南县| 朝阳县| 丽江市| 丹寨县| 福鼎市| 宜君县| 临城县| 温宿县| 泗水县| 安福县| 洪湖市| 桑日县| 尼勒克县| 沈阳市| 晴隆县| 陕西省| 外汇| 夏河县| 华蓥市| 云浮市| 涪陵区| 乐亭县| 枣庄市| 新和县| 久治县| 连云港市| 井研县| 安西县| 伊金霍洛旗| 包头市| 鸡东县| 霍林郭勒市| 文化| 体育| 宜春市| 青田县| 连州市| 神木县| 都匀市| 正安县|