How to use 'python color codes' in Python

Every line of 'python color codes' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
65def get_color_code(cls, color):
66 return cls.CONTROL + color

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

57def _get_ansi_code(color=None, style=None):
58 """return ansi escape code corresponding to color and style
60 :type color: str or None
61 :param color:
62 the color name (see `ANSI_COLORS` for available values)
63 or the color number when 256 colors are available
65 :type style: str or None
66 :param style:
67 style string (see `ANSI_COLORS` for available values). To get
68 several style effects at the same time, use a coma as separator.
70 :raise KeyError: if an unexistent color or style identifier is given
72 :rtype: str
73 :return: the built escape code
74 """
75 ansi_code = []
76 if style:
77 style_attrs = utils._splitstrip(style)
78 for effect in style_attrs:
79 ansi_code.append(ANSI_STYLES[effect])
80 if color:
81 if color.isdigit():
82 ansi_code.extend(["38", "5"])
83 ansi_code.append(color)
84 else:
85 ansi_code.append(ANSI_COLORS[color])
86 if ansi_code:
87 return ANSI_PREFIX + ";".join(ansi_code) + ANSI_END
88 return ""

Related snippets