简单介绍:
此模块儿常用提供和平台无关的命令行输出彩色文字
常用方法:
colorama.init(autoreset=False, convert=None, strip=None, wrap=True) -> colorma
说明:autoreset参数可以让变色效果只对当前输出起作用,输出完成后颜色恢复默认设置
colorama.Fore前景色对象:
BLACK , BLUE , CYAN , GREEN , LIGHTBLACK_EX , LIGHTBLUE_EX , LIGHTCYAN_EX , LIGHTGREEN_EX , LIGHTMAGENTA_EX , LIGHTRED_EX , LIGHTWHITE_EX , LIGHTYELLOW_EX , MAGENTA , RED , RESET(重置) , WHITE , YELLOW ,
colorama.Back背景色对象:
BLACK , BLUE , CYAN , GREEN , LIGHTBLACK_EX , LIGHTBLUE_EX , LIGHTCYAN_EX , LIGHTGREEN_EX , LIGHTMAGENTA_EX , LIGHTRED_EX , LIGHTWHITE_EX , LIGHTYELLOW_EX , MAGENTA , RED , RESET(重置) , WHITE , YELLOW ,
colorama.Style样式对象 :
BRIGHT , DIM , NORMAL , RESET_ALL(重置)
# -*- coding: utf-8 -*- """ # # Authors: limanman # OsChina: http://my.oschina.net/pydevops/ # Purpose: # """ import colorama def get_module_attr(md_obj): """Get module attributes.""" md_attributes = [] for attr in dir(md_obj): if not attr.startswith('_'): md_attributes.append(getattr(md_obj, attr)) return md_attributes def main(): """Main function.""" test_mesgs = 'I Love You!' fore_color = get_module_attr(colorama.Fore) back_color = get_module_attr(colorama.Back) font_style = get_module_attr(colorama.Style) fore_back = [] for i in xrange(0, len(fore_color)): for j in xrange(0, len(back_color)): cur_style = [fore_color[i], back_color[j]] fore_back.append(cur_style) oldstyles = [] for i in xrange(0, len(fore_back)): for j in xrange(0, len(font_style)): cur_style = fore_back[i] + [font_style[j]] oldstyles.append(cur_style) newstyles = [] for style in oldstyles: str_style = ''.join(sorted(style)) newstyles.append(str_style) for style in set(newstyles): print ''.join([style, test_mesgs]), if __name__ == '__main__': colorama.init(autoreset=True) main()
有图有像: