new method for string objects

Andrew Dalke dalke at acm.org
Mon Apr 3 02:00:00 EDT 2000


Fredrik Lundh wrote:
>>>> s = u"123"
>>>> b = buffer(s)
>>>> b
><read-only buffer for 7969b0, ptr 7969d0, size 6 at 796530>
>>>> len(b)
>6
>>>> b[0]
>'1'
>>>> str(b)
>'1\0002\0003\000'
>>>> fp.write(b) # writes raw contents to file without extra copy


BTW, what I'm really surprised about is that the following works:

a = "GAATAAC"
b = buffer(a)
import string
string.count(b, "A")

I guess that's what it means when the string code wants
a "read-only character buffer".  There's something fundamental
I'm missing on how strings and buffers work in Python.  Looks
like it's time to look at source code.

                    Andrew
                    dalke at acm.org






More information about the Python-list mailing list