33
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

コンソールに色付きの出力をする方法

以下を定義して、

bcolors
class pycolor:
    BLACK = '\033[30m'
    RED = '\033[31m'
    GREEN = '\033[32m'
    YELLOW = '\033[33m'
    BLUE = '\033[34m'
    PURPLE = '\033[35m'
    CYAN = '\033[36m'
    WHITE = '\033[37m'
    END = '\033[0m'
    BOLD = '\038[1m'
    UNDERLINE = '\033[4m'
    INVISIBLE = '\033[08m'
    REVERCE = '\033[07m'
main
print pycolor.RED + "RED TEXT" + pycolor.END

と実行すると

RED TEXT

と出力されます。
終わるときには pycolor.ENDをつけるのを忘れないで下さい。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
33
Help us understand the problem. What are the problem?