2015-02-27 20:16:35 +00:00
|
|
|
try:
|
|
|
|
bytearray()[:] = bytearray()
|
|
|
|
except TypeError:
|
|
|
|
print("SKIP")
|
2017-06-10 18:03:01 +01:00
|
|
|
raise SystemExit
|
2015-02-27 20:16:35 +00:00
|
|
|
|
2017-06-30 08:22:17 +01:00
|
|
|
# test slices; only 2 argument version supported by MicroPython at the moment
|
2015-02-27 20:16:35 +00:00
|
|
|
x = bytearray(range(10))
|
|
|
|
|
|
|
|
# Assignment
|
|
|
|
l = bytearray(x)
|
|
|
|
l[1:3] = bytearray([10, 20])
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
l[1:3] = bytearray([10])
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
l[1:3] = bytearray()
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
#del l[1:3]
|
|
|
|
print(l)
|
|
|
|
|
|
|
|
l = bytearray(x)
|
|
|
|
l[:3] = bytearray([10, 20])
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
l[:3] = bytearray()
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
#del l[:3]
|
|
|
|
print(l)
|
|
|
|
|
|
|
|
l = bytearray(x)
|
|
|
|
l[:-3] = bytearray([10, 20])
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
l[:-3] = bytearray()
|
|
|
|
print(l)
|
|
|
|
l = bytearray(x)
|
|
|
|
#del l[:-3]
|
|
|
|
print(l)
|
2015-03-25 23:10:09 +00:00
|
|
|
|
|
|
|
# slice assignment that extends the array
|
|
|
|
b = bytearray(2)
|
|
|
|
b[2:] = bytearray(10)
|
|
|
|
print(b)
|
2015-04-15 22:48:36 +01:00
|
|
|
|
2016-03-14 23:12:54 +00:00
|
|
|
b = bytearray(10)
|
|
|
|
b[:-1] = bytearray(500)
|
|
|
|
print(len(b), b[0], b[-1])
|
2015-04-15 22:48:36 +01:00
|
|
|
|
2017-04-02 08:31:32 +01:00
|
|
|
# extension with self on RHS
|
|
|
|
b = bytearray(x)
|
|
|
|
b[4:] = b
|
|
|
|
print(b)
|
|
|
|
|
2015-04-15 22:48:36 +01:00
|
|
|
# Assignment of bytes to array slice
|
|
|
|
b = bytearray(2)
|
|
|
|
b[1:1] = b"12345"
|
|
|
|
print(b)
|