mirror of
https://github.com/kennethreitz/crayons.git
synced 2026-06-05 15:00:18 +00:00
Handle passing non-string types into crayons
Signed-off-by: Matthew Peveler <matt.peveler@gmail.com>
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user