[issue45087] Confusing error message when trying split bytes.

Eric V. Smith report at bugs.python.org
Thu Sep 2 16:28:26 EDT 2021


Eric V. Smith <eric at trueblade.com> added the comment:

This is working as designed. The error is telling you that the argument to bytes.split() must be a string:

>>> b''.split(',')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: a bytes-like object is required, not 'str'

>>> b''.split(b',')
[b'']

Same for str.split():

>>> ''.split(b',')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: must be str or None, not bytes

>>> ''.split(',')
['']

----------
components:  -Argument Clinic
nosy: +eric.smith -larry

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45087>
_______________________________________


More information about the Python-bugs-list mailing list