From 775160f51eec48a39b8580463c2a20636fbf0f95 Mon Sep 17 00:00:00 2001 From: Dirk Thomas Date: Fri, 21 Jul 2017 11:08:30 -0700 Subject: [PATCH] fix rostopic prining long integers --- tools/rostopic/src/rostopic/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/rostopic/src/rostopic/__init__.py b/tools/rostopic/src/rostopic/__init__.py index f33bf0ab29..c32e33efff 100644 --- a/tools/rostopic/src/rostopic/__init__.py +++ b/tools/rostopic/src/rostopic/__init__.py @@ -64,6 +64,12 @@ #TODO: lazy-import rospy or move rospy-dependent routines to separate location import rospy +try: + long +except NameError: + long = int + + class ROSTopicException(Exception): """ Base exception class of rostopic-related errors @@ -687,7 +693,7 @@ def _sub_str_plot_fields(val, f, field_filter): """recursive helper function for _str_plot_fields""" # CSV type_ = type(val) - if type_ in (bool, int, float) or \ + if type_ in (bool, int, long, float) or \ isinstance(val, genpy.TVal): return f # duck-type check for messages @@ -708,7 +714,7 @@ def _sub_str_plot_fields(val, f, field_filter): val0 = val[0] type0 = type(val0) # no arrays of arrays - if type0 in (bool, int, float) or \ + if type0 in (bool, int, long, float) or \ isinstance(val0, genpy.TVal): return ','.join(["%s%s"%(f,x) for x in range(0,len(val))]) elif _isstring_type(type0): @@ -757,7 +763,7 @@ def _sub_str_plot(val, time_offset, field_filter): if type_ == bool: return '1' if val else '0' - elif type_ in (int, float) or \ + elif type_ in (int, long, float) or \ isinstance(val, genpy.TVal): if time_offset is not None and isinstance(val, genpy.Time): return str(val-time_offset) @@ -783,7 +789,7 @@ def _sub_str_plot(val, time_offset, field_filter): type0 = type(val0) if type0 == bool: return ','.join([('1' if v else '0') for v in val]) - elif type0 in (int, float) or \ + elif type0 in (int, long, float) or \ isinstance(val0, genpy.TVal): return ','.join([str(v) for v in val]) elif _isstring_type(type0):