← index #6346Issue #6096
Off-topic · high · value 1.766
QUERY · ISSUE

Class `bytearray()` does not implement `count()`

openby mirkoopened 2020-08-19updated 2024-10-01
enhancementpy-core

I just noticed that micropython apparently doesn't implement the count() method for class bytearray().
Since it's a basic built-in class/type and I didn't find it anywhere mentioned (docs/issues), I figured it might be worth dropping it here.

CPython:

bytearray(b'foobar').count(b'o')
2

MicroPython:

>>> bytearray(b'foobar').count(b'o')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'bytearray' object has no attribute 'count'
CANDIDATE · ISSUE

Bytearray slice assignement throwing exception on ESP32 idf v4.

closedby tionebrropened 2020-05-30updated 2020-05-31

Following the example in the documentation:
https://docs.micropython.org/en/latest/genrst/builtin_types.html#bytearray

>>> b = bytearray(4)
>>> b[0:1] = [1, 2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NotImplementedError: array/bytes required on right 
>>> print(b)
bytearray(b'\x00\x00\x00\x00')

I noticed that assigning b'\x01\x02' works.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied