diff options
author | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-02-26 05:53:54 -0700 |
---|---|---|
committer | David Luevano Alvarado <55825613+luevano@users.noreply.github.com> | 2020-02-26 05:53:54 -0700 |
commit | e18a909d18481e5e292882b3b1dd2ad8d693d097 (patch) | |
tree | c0137e2444ece8715681c9cc1bef212d3d3d4fac /ml_exp/misc.py | |
parent | b209f5e79ce45e6a4d5b442f10217806d078d5a6 (diff) |
Revise printc
Diffstat (limited to 'ml_exp/misc.py')
-rw-r--r-- | ml_exp/misc.py | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/ml_exp/misc.py b/ml_exp/misc.py index e9142b05f..4bd68eefc 100644 --- a/ml_exp/misc.py +++ b/ml_exp/misc.py @@ -29,29 +29,25 @@ init() def printc(text, color): """ Prints texts normaly, but in color. Using colorama. - text: string with the text to print. + text: text to print. color: color to be used, same as available in colorama. """ - color_dic = {'BLACK': Fore.BLACK, - 'RED': Fore.RED, - 'GREEN': Fore.GREEN, - 'YELLOW': Fore.YELLOW, - 'BLUE': Fore.BLUE, - 'MAGENTA': Fore.MAGENTA, - 'CYAN': Fore.CYAN, - 'WHITE': Fore.WHITE, - 'RESET': Fore.RESET} - - color_dic_keys = color_dic.keys() - if color not in color_dic_keys: - print(Fore.RED - + '\'{}\' not found, using default color.'.format(color) - + Style.RESET_ALL) - actual_color = Fore.RESET - else: - actual_color = color_dic[color] - - print(actual_color + text + Style.RESET_ALL) + color = color.upper() + colors = {'BLACK': Fore.BLACK, + 'RED': Fore.RED, + 'GREEN': Fore.GREEN, + 'YELLOW': Fore.YELLOW, + 'BLUE': Fore.BLUE, + 'MAGENTA': Fore.MAGENTA, + 'CYAN': Fore.CYAN, + 'WHITE': Fore.WHITE, + 'RESET': Fore.RESET} + + av_colors = colors.keys() + if color not in av_colors: + raise KeyError(f'{color} not found.') + + print(colors[color] + text + Style.RESET_ALL) def plot_benchmarks(): |