[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r10401 - gnuradio/trunk/grc/src/platforms/python
From: |
jblum |
Subject: |
[Commit-gnuradio] r10401 - gnuradio/trunk/grc/src/platforms/python |
Date: |
Thu, 5 Feb 2009 16:18:48 -0700 (MST) |
Author: jblum
Date: 2009-02-05 16:18:47 -0700 (Thu, 05 Feb 2009)
New Revision: 10401
Modified:
gnuradio/trunk/grc/src/platforms/python/Param.py
Log:
better type checking in repr
Modified: gnuradio/trunk/grc/src/platforms/python/Param.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/python/Param.py 2009-02-05 22:55:06 UTC
(rev 10400)
+++ gnuradio/trunk/grc/src/platforms/python/Param.py 2009-02-05 23:18:47 UTC
(rev 10401)
@@ -98,16 +98,15 @@
##################################################
# display logic for numbers
##################################################
- def to_str(num):
- if isinstance(num, str): return num
- elif isinstance(num, complex):
+ def num_to_str(num):
+ if isinstance(num, COMPLEX_TYPES):
+ num = complex(num) #cast to python complex
if num == 0: return '0' #value is zero
elif num.imag == 0: return
'%s'%eng_notation.num_to_str(num.real) #value is real
elif num.real == 0: return
'%sj'%eng_notation.num_to_str(num.imag) #value is imaginary
elif num.imag < 0: return
'%s-%sj'%(eng_notation.num_to_str(num.real),
eng_notation.num_to_str(abs(num.imag)))
else: return
'%s+%sj'%(eng_notation.num_to_str(num.real), eng_notation.num_to_str(num.imag))
- elif isinstance(num, (float, int)): return
eng_notation.num_to_str(num)
- else: return str(var)
+ else: return str(num)
##################################################
# split up formatting by type
##################################################
@@ -115,16 +114,16 @@
max_len = max(27 - len(self.get_name()), 3)
e = self.evaluate()
t = self.get_type()
- if t in ('int', 'real', 'complex'): dt_str = to_str(e)
- elif isinstance(e, (list, tuple, set, numpy.ndarray)): #vector
types
+ if isinstance(e, COMPLEX_TYPES): dt_str = num_to_str(e)
+ elif isinstance(e, VECTOR_TYPES): #vector types
if len(e) > 8:
dt_str = self.get_value() #large vectors use
code
truncate = 1
- else: dt_str = ', '.join(map(to_str, e)) #small vectors
use eval
+ else: dt_str = ', '.join(map(num_to_str, e)) #small
vectors use eval
elif t in ('file_open', 'file_save'):
dt_str = self.get_value()
truncate = -1
- else: dt_str = to_str(e) #other types
+ else: dt_str = str(e) #other types
##################################################
# truncate
##################################################
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r10401 - gnuradio/trunk/grc/src/platforms/python,
jblum <=