Skip to content


Python: wrapper around termcolor to allow enable/disable

class Color(object):
  """Wrapper around termcolor to allow colors to be disabled."""

  @classmethod
  def Setup(cls, enabled=True):
    if enabled:
      cls.me = cls.WithColor
    else:
      cls.me = cls.WithoutColor

  @classmethod
  def WithColor(cls, msg, color=None, on_color=None, attrs=None):
    return termcolor.colored(msg, color, on_color, attrs)

  @classmethod
  def WithoutColor(cls, msg, color=None, on_color=None, attrs=None):
    (color, on_color, attrs) = (color, on_color, attrs)  # gpylint
    return msg

Posted in Uncategorized.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.