summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python/gnuradio/eng_notation.py
diff options
context:
space:
mode:
Diffstat (limited to 'gnuradio-runtime/python/gnuradio/eng_notation.py')
-rw-r--r--gnuradio-runtime/python/gnuradio/eng_notation.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/gnuradio-runtime/python/gnuradio/eng_notation.py b/gnuradio-runtime/python/gnuradio/eng_notation.py
index 391dc5838f..ec35b0db5b 100644
--- a/gnuradio-runtime/python/gnuradio/eng_notation.py
+++ b/gnuradio-runtime/python/gnuradio/eng_notation.py
@@ -23,6 +23,9 @@ Display numbers as strings using engineering notation.
"""
from __future__ import unicode_literals
+import six
+
+
scale_factor = {}
scale_factor['E'] = 1e18
scale_factor['P'] = 1e15
@@ -66,11 +69,13 @@ def num_to_str (n, precision=6):
def str_to_num (value):
'''Convert a string in engineering notation to a number. E.g., '15m' -> 15e-3'''
try:
+ if not isinstance(value, six.string_types):
+ raise TypeError("Value must be a string")
scale = 1.0
suffix = value[-1]
if suffix in scale_factor:
return float (value[0:-1]) * scale_factor[suffix]
return float (value)
- except:
- raise RuntimeError (
+ except (TypeError, KeyError, ValueError):
+ raise ValueError (
"Invalid engineering notation value: %r" % (value,))