← index #5123Issue #567
Off-topic · high · value 0.956
QUERY · ISSUE

bytes.find() differs from CPython

openby doc-hexopened 2019-09-19updated 2019-09-26
py-core

In Cpython (at least) I can find by integer using bytes.find(). Micropython doesn't allow this and only acceptsbytes as an argument to find.

Micropython:

>>> s = b'ABC'
>>> s.find(b'B')
1
>>> s.find(66)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'int' object to str implicitly
>>> 

Desktop python:

>>> s = b'ABC'
>>> s.find(b'B')
1
>>> s.find(66)
1

Here is the check that's failing, but additional code would be needed to convert int (0..255) into byte.

https://github.com/micropython/micropython/blob/master/py/objstr.c#L693

This bug bit me deep in some QR encoding logic.

CANDIDATE · ISSUE

bytes builtin doesn't accept encoding kwarg

closedby lurchopened 2014-05-05updated 2020-03-23

Dunno if this is a known problem or has been reported before, but searching for 'bytes' obviously throws up a hell of a lot of matches! ;)

On CPython, I can do both bytes('hello', 'ascii') and bytes('hello', encoding='ascii').
On uPy, the former works, but the latter fails with
TypeError: wrong number of arguments

I also just spotted that on CPython both str(b'hello', 'ascii') and str(b'hello', encoding='ascii') produce the same result, but on uPy the second version returns something quite different. (let me know if I should split that off into a separate issue)

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