From c025c32a3d4eb5d2f95b744109bebdcf9b9bfcdb Mon Sep 17 00:00:00 2001 From: nojhan Date: Wed, 3 Apr 2013 19:02:04 +0200 Subject: [PATCH] Conditional import of babel, fallback to std parsing --- colout.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/colout.py b/colout.py index 6f68d6b..9dc67bf 100644 --- a/colout.py +++ b/colout.py @@ -116,10 +116,12 @@ def colorin(text, color="red", style="normal"): colormap_idx = 0 elif color == "scale": - mode = 8 - import babel.numbers as bn import math - f = float(bn.parse_decimal(text)) + try: + import babel.numbers as bn + f = float(bn.parse_decimal(text)) + except ImportError: + f = float(text) # if out of scale, do not color if f < scale[0] or f > scale[1]: @@ -128,6 +130,7 @@ def colorin(text, color="red", style="normal"): # normalize and scale over the nb of colors in colormap i = int( math.ceil( (f - scale[0]) / (scale[1]-scale[0]) * (len(colormap)-1) ) ) + mode = 8 color = colormap[i] color_code = str(30 + colors[color])