How to create a writeable buffer?

S

Steve Chaplin

I'm trying to create an object (as a C extension) to support the buffer
interface and was getting "TypeError: buffer is read-only" errors. So I
had a look at the array object and it has the same problem:

$ python
>>> import array
>>> a=array.array('c', ['a', 'b', 'c'])
>>> a array('c', 'abc')
>>> a[0] 'a'
>>> a[0]='d'
>>> a array('c', 'dbc')
>>> buf=buffer(a)
>>> buf[0] 'd'
>>> buf[0]='e'
TypeError: buffer is read-only

The array is a mutable (writable) object, and the array implements the
buffer interface and provides a 'getwritebuf' method.
(Python-2.4.4/Modules/arraymodule.c has an array_buffer_getwritebuf())
so why does it give "TypeError: buffer is read-only"?

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top