summaryrefslogtreecommitdiff
path: root/ml_exp/misc.py
diff options
context:
space:
mode:
authorDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-02-26 05:53:54 -0700
committerDavid Luevano Alvarado <55825613+luevano@users.noreply.github.com>2020-02-26 05:53:54 -0700
commite18a909d18481e5e292882b3b1dd2ad8d693d097 (patch)
treec0137e2444ece8715681c9cc1bef212d3d3d4fac /ml_exp/misc.py
parentb209f5e79ce45e6a4d5b442f10217806d078d5a6 (diff)
Revise printc
Diffstat (limited to 'ml_exp/misc.py')
-rw-r--r--ml_exp/misc.py38
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():