{"id":6803,"date":"2014-11-05T09:45:43","date_gmt":"2014-11-05T01:45:43","guid":{"rendered":"http:\/\/jpuyy.com\/?p=6803"},"modified":"2014-11-12T13:55:13","modified_gmt":"2014-11-12T05:55:13","slug":"python-print-color","status":"publish","type":"post","link":"https:\/\/jpuyy.com\/?p=6803","title":{"rendered":"python print\u989c\u8272"},"content":{"rendered":"<p>\u5b9a\u4e49\u4e00\u4e2aclass<\/p>\n<pre>class bcolors:\r\n    HEADER = '\\033[95m'           # \u7c89\u8272\r\n    OKBLUE = '\\033[94m'           # \u84dd\u8272\r\n    OKGREEN = '\\033[92m'          # \u7eff\u8272\r\n    WARNING = '\\033[93m'          # \u9ec4\u8272\r\n    FAIL = '\\033[91m'             # \u7ea2\u8272\r\n    BOLD = '\\033[1m'              # \u7c97\u4f53\r\n    ENDC = '\\033[0m'              # \u7ed3\u675f\r\n<\/pre>\n<p>\u4e0d\u7ba1\u663e\u793a\u54ea\u79cd\u989c\u8272\uff0c\u6700\u540e\u90fd\u9700\u8981\u7528end\u7ed3\u675f\uff0c\u4e0d\u7136\u4f1a\u4e00\u76f4\u6e32\u67d3\u3002<\/p>\n<pre>print bcolors.WARNING + \"Warning: No active frommets remain. Continue?\" + bcolors.ENDC<\/pre>\n<p>\u53c2\u8003\uff1a<br \/>\nhttp:\/\/stackoverflow.com\/questions\/287871\/print-in-terminal-with-colors-using-python<\/p>\n<p>\u5176\u4ed6\u989c\u8272\u53ef\u4ee5\u53c2\u8003<\/p>\n<pre>\r\n#!\/usr\/bin\/perl\r\nprint \"0\\t\\033[0m coloured! \\033[m\\n\";\r\nprint \"1\\t\\033[1m coloured! \\033[m\\n\";\r\nprint \"4\\t\\033[4m coloured! \\033[m\\n\";\r\nprint \"7\\t\\033[7m coloured! \\033[m\\n\";\r\nprint \"31\\t\\033[31m coloured! \\033[m\\n\";\r\nprint \"32\\t\\033[32m coloured! \\033[m\\n\";\r\nprint \"33\\t\\033[33m coloured! \\033[m\\n\";\r\nprint \"34\\t\\033[34m coloured! \\033[m\\n\";\r\nprint \"35\\t\\033[35m coloured! \\033[m\\n\";\r\nprint \"36\\t\\033[36m coloured! \\033[m\\n\";\r\nprint \"37\\t\\033[37m coloured! \\033[m\\n\";\r\nprint \"38\\t\\033[38m coloured! \\033[m\\n\";\r\nprint \"39\\t\\033[39m coloured! \\033[m\\n\";\r\nprint \"40\\t\\033[40m coloured! \\033[m\\n\";\r\nprint \"41\\t\\033[41m coloured! \\033[m\\n\";\r\nprint \"42\\t\\033[42m coloured! \\033[m\\n\";\r\nprint \"43\\t\\033[43m coloured! \\033[m\\n\";\r\nprint \"44\\t\\033[44m coloured! \\033[m\\n\";\r\nprint \"45\\t\\033[45m coloured! \\033[m\\n\";\r\nprint \"46\\t\\033[46m coloured! \\033[m\\n\";\r\nprint \"47\\t\\033[47m coloured! \\033[m\\n\";\r\nprint \"90\\t\\033[90m coloured! \\033[m\\n\";\r\nprint \"91\\t\\033[91m coloured! \\033[m\\n\";\r\nprint \"92\\t\\033[92m coloured! \\033[m\\n\";\r\nprint \"93\\t\\033[93m coloured! \\033[m\\n\";\r\nprint \"94\\t\\033[94m coloured! \\033[m\\n\";\r\nprint \"95\\t\\033[95m coloured! \\033[m\\n\";\r\nprint \"96\\t\\033[96m coloured! \\033[m\\n\";\r\nprint \"97\\t\\033[97m coloured! \\033[m\\n\";\r\nprint \"98\\t\\033[98m coloured! \\033[m\\n\";\r\nprint \"99\\t\\033[99m coloured! \\033[m\\n\";\r\nprint \"100\\t\\033[100m coloured! \\033[m\\n\";\r\nprint \"101\\t\\033[101m coloured! \\033[m\\n\";\r\nprint \"102\\t\\033[102m coloured! \\033[m\\n\";\r\nprint \"103\\t\\033[103m coloured! \\033[m\\n\";\r\nprint \"104\\t\\033[104m coloured! \\033[m\\n\";\r\nprint \"105\\t\\033[105m coloured! \\033[m\\n\";\r\nprint \"106\\t\\033[106m coloured! \\033[m\\n\";\r\nprint \"107\\t\\033[107m coloured! \\033[m\\n\";\r\nprint \"108\\t\\033[108m coloured! \\033[m\\n\";\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u4e49\u4e00\u4e2aclass class bcolors: HEADER = &#8216;\\033[95m&#8217; # \u7c89\u8272 OKBLUE = &#8216;\\033[94m&#8217; # \u84dd\u8272 OKGREEN = &#8216;\\033[92m&#8217; # \u7eff\u8272 WARNING = &#8216;\\033[93m&#8217; # \u9ec4\u8272 FAIL = &#8216;\\033[91m&#8217; # \u7ea2\u8272 BOLD = &#8216;\\033[1m&#8217; # \u7c97\u4f53 ENDC = &#8216;\\033[0m&#8217; # \u7ed3\u675f \u4e0d\u7ba1\u663e\u793a\u54ea\u79cd\u989c\u8272\uff0c\u6700\u540e\u90fd\u9700\u8981\u7528end\u7ed3\u675f\uff0c\u4e0d\u7136\u4f1a\u4e00\u76f4\u6e32\u67d3\u3002 print bcolors.WARNING + &#8220;Warning: No active frommets remain. Continue?&#8221; + bcolors.ENDC \u53c2\u8003\uff1a http:\/\/stackoverflow.com\/questions\/287871\/print-in-terminal-with-colors-using-python \u5176\u4ed6\u989c\u8272\u53ef\u4ee5\u53c2\u8003 #!\/usr\/bin\/perl print [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[76],"tags":[],"class_list":["post-6803","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6803","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6803"}],"version-history":[{"count":2,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6803\/revisions"}],"predecessor-version":[{"id":6845,"href":"https:\/\/jpuyy.com\/index.php?rest_route=\/wp\/v2\/posts\/6803\/revisions\/6845"}],"wp:attachment":[{"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6803"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6803"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jpuyy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6803"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}