Last active
August 29, 2015 14:02
-
-
Save genba/5941879b5e5820008213 to your computer and use it in GitHub Desktop.
Python print functions to stdout and stderr using termcolor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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