diff --git a/crayons.py b/crayons.py index cd79a74..80b99c5 100644 --- a/crayons.py +++ b/crayons.py @@ -47,7 +47,7 @@ class ColoredString(object): if not PY3 and isinstance(s, unicode): # noqa: F821 self.s = s.encode('utf-8') else: - self.s = s + self.s = str(s) self.color = REPLACE_COLORS.get(color, color) self.always_color = always_color self.bold = bold diff --git a/test_crayons.py b/test_crayons.py index fd07d0f..6dc492f 100755 --- a/test_crayons.py +++ b/test_crayons.py @@ -8,8 +8,10 @@ print(crayons.red('red string')) print('{} white {}'.format(crayons.red('red'), crayons.blue('blue'))) crayons.disable() print('{} white {}'.format(crayons.red('red'), crayons.blue('blue'))) +print('non-string value {!s}'.format(crayons.red(1234))) crayons.enable() print('{} white {}'.format(crayons.red('red'), crayons.blue('blue'))) +print('non-string value {!s}'.format(crayons.red(1234))) print(crayons.red('red string', bold=True)) print(crayons.yellow('yellow string', bold=True)) print(crayons.magenta('magenta string', bold=True))