[Python-Dev] Crazy idea for str.join

Josiah Carlson jcarlson at uci.edu
Sun Apr 30 00:11:58 CEST 2006


Thomas Heller <theller at python.net> wrote:
> 
> Fredrik Lundh wrote:
> > Josiah Carlson wrote:
> > 
> >> At least for the examples of buffers that I've seen, using the buffer
> >> interface for objects that support it is equivalent to automatically
> >> applying str() to them.  This is, strictly speaking, an optimization.
> > 
> >     >>> a = array.array("i", [1, 2, 3])
> >     >>> str(a)
> >     "array('i', [1, 2, 3])"
> >     >>> str(buffer(a))
> >     '\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00'
> 
> or:
> 
> thomas at tubu:~$ python2.4
> Python 2.4.2 (#2, Sep 30 2005, 22:19:27)
> [GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> str(buffer(u"abc"))
> 'a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00'
> >>>

Hrm, those are interesting examples.  It would seem as though checking
to see if a passed object was a buffer itself, rather than whether it
supported the buffer interface, would be more correct.

 - Josiah



More information about the Python-Dev mailing list