New submission from Timothy Pederick <peder...@gmail.com>:

This code behaves as expected:
>>> ' '.join('cat')
'c a t'

This code does not:
>>> b'\x00'.join(b'cat')
Traceback (most recent call last):
  ...
    b'\x00'.join(b'cat')
TypeError: sequence item 0: expected bytes, int found

Instead, you have to do something like this:
>>> b'\x00'.join(bytes((i,)) for i in b'cat')
b'c\x00a\x00t'

The cause is that indexing a bytes object gives an int, not a bytes. I know, 
it's as designed, PEP 3137, etc. But in this specific instance, it causes 
Python to behave inconsistently (bytes vs. str) and unintuitively (to me, 
anyway).

(Same problem with bytes or bytearray in either position.)

----------
files: joinerror.py
messages: 105317
nosy: perey
priority: normal
severity: normal
status: open
title: bytes join cannot join bytes
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file17262/joinerror.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue8662>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to