I want to trim a bytes string before an index found by locating $$$
,
trimmed_bytes_stream = padded_bytes_stream[:padded_stream.index('$$$')]
but got an error:
TypeError: a bytes-like object is required, not 'str'
Is there bytes object equivalent methods to do that? Or have convert bytes string to string and then using string methods? finally convert back to bytes after trimming?
Append a b
to your search item
trimmed_bytes_stream = padded_bytes_stream[:padded_stream.index(b'$$$')]