2019.3
add printing behavior for results and models
@@ -177,6 +177,28 @@ cdef data_or_file * mk_data_or_file(object x):
x = [x.values]
return new data_or_file(<PyObject *>x)
+
+def _str(instance, properties):
+ result = ''
+ for p in properties:
+ prop = getattr(instance, p, None)
+ tail = ''
+ if isinstance(prop, np.ndarray):
+ result += p + ': array('
+ tail = ',\\n dtype={}, shape={})'.format(prop.dtype,
+ prop.shape)
+ elif isinstance(prop, dict):
+ result += p + ': dict, len={}'.format(len(prop))
+ else:
+ result += p + ': '
+ value = '\\n '.join(str(prop).splitlines())
+ if '\\n' in value or isinstance(prop, np.ndarray):
+ result += '\\n '
+ result += value
+ result += tail
+ result += '\\n\\n'
+ return result[:-2]
+
'''
###############################################################################
@@ -268,6 +290,8 @@ cdef class {{flatname}}:
def __init__(self, int64_t ptr=0):
self.c_ptr = <{{class_type|flat}}>ptr
+ def __str__(self):
+ return _str(self, [{% for m in enum_gets+named_gets %}'{{m[1]}}',{% endfor %}])
{% for m in enum_gets+named_gets %}
{% set rtype = m[2]|d2cy(False) if m in enum_gets else m[0]|d2cy(False) %}
