[Tutor] Re: Need help on modifying buffer passed to python script from c

Shantanu Mahajan python@dhumketu.cjb.net
Sun Jun 8 01:26:01 2003


+-- R. Alan Monroe [python-tutor] [07-06-03 10:09 -0400]:
| Here are the relevant parts of the c program
| 
| PyObject *themodule, *thefunc, *theresult, *thebuf;
| int themem[100];
| themem[0] = 26;
| thebuf = PyBuffer_FromReadWriteMemory(themem, 100);
| theresult = PyObject_CallFunctionObjArgs( thefunc, thebuf, NULL);
| 
| ... and the python script
| 
| def render( thepointer ):
|     print "python thepointer[0] ", thepointer[0]  # an arrow character
|     print "python type(thepointer) ", type(thepointer)  # <type 'buffer'>
|     print "python type(thepointer[0]) ", type(thepointer[0])  #  <type 'str'>
|     print "python ord(thepointer[0]) ", ord(thepointer[0])  # 26, as expected
|     thepointer[0] += 1   #<--- program error, can't increment a string

	thepointer[0] = str(int(thepointer[0]+1)
| 
| This is for the Sonique vis plugin I mentioned a few days ago. The
| problem I'm running into is that python thinks the buffer is a big
| string, but I want it to be treated as integers (it's an offscreen
| ARGB buffer to be blitted to the screen). Is there a way of "tricking"
| Python into seeing it as something other than 'str'?
| 
| 
| Alan

	Regards,
	Shantanu
-- 
Want to know how many words, lines, or bytes are contained in a file? Type
"wc filename".
		-- Dru <genesis@istar.ca>