new method for string objects

Fredrik Lundh effbot at
Sat Apr 1 09:23:25 EST 2000

Andrew Dalke <dalke at> wrote:
>   I know with 1.6 strings will have methods.  If it isn't
> already there, I would like to propose an additional method,
> "tostring()", which returns itself.
>   I'm working on a project which may use array.array of
> characters, Numeric.array, or a string, and I would like
> to have a way that's guaranteed to return the string
> value for the object.

assuming that "string value" means the "raw contents of the
sequence object", you should use a buffer objects instead.
you can use the 'buffer' builtin to turn most sequence objects
into buffers:

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

(if numeric python doesn't support the buffer interface,
it should be fixed).


More information about the Python-list mailing list