Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
1801421f
Commit
1801421f
authored
Jan 28, 2014
by
Paul Sokolovsky
Browse files
bytearray: Print objects properly.
parent
0b7e29c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objarray.c
View file @
1801421f
...
...
@@ -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
,
")"
);
}
...
...
tests/basics/bytearray1.py
View file @
1801421f
a
=
bytearray
([
1
,
2
,
200
])
print
(
a
[
0
],
a
[
2
])
print
(
a
[
-
1
])
print
(
a
)
a
[
2
]
=
255
print
(
a
[
-
1
])
a
.
append
(
10
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment