[Python-Dev] Crazy idea for str.join

Josiah Carlson jcarlson at uci.edu
Sat Apr 29 15:12:29 CEST 2006


I understand the underlying implementation of str.join can be a bit
convoluted (with the auto-promotion to unicode and all), but I don't
suppose there is any chance to get str.join to support objects which
implement the buffer interface as one of the items in the sequence?

Something like:
    
    y = 'hello world'
    buf1 = buffer(y, 0, 5)
    buf2 = buffer(y, 6)
    print ''.join([buf1, buf2])

should print "helloworld"

It would take a PyBuffer_Check() just after the PyUnicode_Check() block.
And one may be able to replace the other PyString_* calls with
PyObject_AsCharBuffer() calls.

I'm not going to push for this, but someone other than me may find such
functionality useful.

 - Josiah

P.S. One interesting thing to note is that quite a few underlying
objects take buffer objects in lieu of strings, even when they aren't
documented as doing so; file.write(), array.fromstring(), mmap[i:j] =
buffer, etc.



More information about the Python-Dev mailing list