Skip to content

Instantly share code, notes, and snippets.

@genba
Last active August 29, 2015 14:02
Show Gist options
  • Save genba/5941879b5e5820008213 to your computer and use it in GitHub Desktop.
Save genba/5941879b5e5820008213 to your computer and use it in GitHub Desktop.
Python print functions to stdout and stderr using termcolor
import sys
try:
from termcolor import colored
except ImportError:
def colored(msg, *args, **kwargs):
return msg
def print_info(msg, color='', *args, **kwargs):
if color == '':
sys.stdout.write(msg)
else:
sys.stdout.write(colored(msg, color, *args, **kwargs))
def print_error(msg, color='', *args, **kwargs):
if color == '':
sys.stderr.write(msg)
else:
sys.stderr.write(colored(msg, color, *args, **kwargs))
def print_success(msg, color='green', *args, **kwargs):
print_info(msg, color, *args, **kwargs)
def print_failure(msg, color='red', *args, **kwargs):
print_info(msg, color, *args, **kwargs)
def print_warning(msg, color='yellow', *args, **kwargs):
print_info(msg, color, *args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment