如何向控制台輸出彩色列印資訊呢?如何訂製自己的輸出格式呢?下面將告訴你……
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!
")
參考:
declare styleable自定義控制項的屬性
name custom background format reference color 1,reference 引入某一資源id 2,color 輸入顏色值 3 boolean 輸入true或者false 4,dimension 輸入尺寸如20dp等 5,enum 列舉值 6,flag 位或者運...
Android 自定義ViewGroup控制項
實現乙個簡單的組合viewgroup控制項topbar 首先要在values目錄下建立乙個attrs.xml檔案,設定一些自定義控制項的屬性 然後建立乙個自定義控制項繼承viewgroup,這裡直接繼承relativelayout public class topbar extends relati...
自定義引數 Python自定義函式引數
1.種類 1 位置引數 x就是位置引數 usr bin env python coding utf 8 def power x result x x print result 2 預設引數n就是預設引數 usr bin env python coding utf 8 def power x,n 1 ...