python 自定义linux控制台输出
2012-03-16 23:25
309 查看
如何向控制台输出彩色打印信息呢?如何订制自己的输出格式呢?下面将告诉你……
输出:
参考:
http://www.oschina.net/code/snippet_87675_8599
http://pypi.python.org/pypi/termcolor/0.1.1#downloads
import os """ 0 All attributes off 默认值 1 Bold (or Bright) 粗体 or 高亮 4 Underline 下划线 5 Blink 闪烁 7 Reverse 反显 30 Black text 31 Red text 32 Green text 33 Yellow text 34 Blue text 35 Purple text 36 Cyan text 37 White text 40 Black background 41 Red background 42 Green background 43 Yellow background 44 Blue background 45 Purple background 46 Cyan background 47 White background """ def colored(text, color=None, on_color=None, attrs=None): fmt_str = '\x1B[;%dm%s\x1B[0m' if color is not None: text = fmt_str % (color, text) if on_color is not None: text = fmt_str % (on_color, text) if attrs is not None: for attr in attrs: text = fmt_str % (color, text) return text def printError(msg): print colored(msg, color=31) def printWarning(msg): print colored(msg, color=33) def printInfo(msg): print colored(msg, color=37) if __name__ == '__main__': printError("this is an error message!") printWarning("this is a warning message!") printInfo("this ia a info message!")
输出:
参考:
http://www.oschina.net/code/snippet_87675_8599
http://pypi.python.org/pypi/termcolor/0.1.1#downloads
相关文章推荐
- Python3.5 控制台日志输出,区分标准输出与错误输出
- 【Python】同时向控制台和文件输出日志logging
- [Python]linux自定义Python脚本命令
- Linux下查看Tomcat的控制台输出信息
- PHP内置Web Server探究(二)自定义PHP控制台输出console函数
- Sublime Text 3 运行Python控制台不能输出中文的解决方法
- Linux(9)后台运行python程序并输出到日志文件
- Python print 输出到控制台 丢数据
- Mac python 下控制台输出汉字
- python通过colorama模块在控制台输出彩色文字的方法
- Python在Linux | Windows中输出带颜色的文字的方法
- Sublime Text 3 运行Python控制台不能输出中文的解决方法
- 两步实现Log4j记录java控制台输出的系统所有异常信息和自定义记录日志---->非常实用,强烈推荐阅读
- Python控制台输出颜色
- python 控制台输出中文乱码问题
- Python构造自定义方法来美化字典结构输出的示例
- python在linux中输出带颜色的文字的方法
- python 控制台同一位置输出
- python nohup linux 后台运行输出