From 1801421f6d204dfae9453187e1f70e261b230a9e Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky <pfalcon@users.sourceforge.net> Date: Tue, 28 Jan 2014 03:40:48 +0200 Subject: [PATCH] bytearray: Print objects properly. --- py/objarray.c | 19 ++++++++++--------- tests/basics/bytearray1.py | 1 + 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/py/objarray.c b/py/objarray.c index ef5fe8ffe..9911e89df 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -124,19 +124,20 @@ static void array_set_el(mp_obj_array_t *o, int index, mp_obj_t val_in) { static void array_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_array_t *o = o_in; if (o->typecode == BYTEARRAY_TYPECODE) { - print(env, "bytearray(", o->typecode); + print(env, "bytearray(b", o->typecode); + mp_str_print_quoted(print, env, o->items, o->len); } else { print(env, "array('%c'", o->typecode); - } - if (o->len > 0) { - print(env, ", [", o->typecode); - for (int i = 0; i < o->len; i++) { - if (i > 0) { - print(env, ", "); + if (o->len > 0) { + print(env, ", [", o->typecode); + for (int i = 0; i < o->len; i++) { + if (i > 0) { + print(env, ", "); + } + print(env, "%d", array_get_el(o, i)); } - print(env, "%d", array_get_el(o, i)); + print(env, "]"); } - print(env, "]"); } print(env, ")"); } diff --git a/tests/basics/bytearray1.py b/tests/basics/bytearray1.py index 3658713fa..3111832f6 100644 --- a/tests/basics/bytearray1.py +++ b/tests/basics/bytearray1.py @@ -1,6 +1,7 @@ a = bytearray([1, 2, 200]) print(a[0], a[2]) print(a[-1]) +print(a) a[2] = 255 print(a[-1]) a.append(10) -- GitLab