Py_ParseTuple Problem
Terry Reedy
tjreedy at udel.edu
Wed Apr 21 13:33:43 EDT 2004
<youngdubliner at hotmail.com> wrote in message
news:4039221c.0404202256.3f21d817 at posting.google.com...
> Hi All ,
>
> Bit of a problem with Py_Parse or Py_ParseTuple ?
>
> I have a python script that reads a sector of flash in an embedded
device.
> it returns the value of each byte within the sector as a tuple.
>
> i.e. [255,255,255,255,255,255,255, .......etc etc for the whole sector !
As written, above is a list instead of a tuple.
> We are using this script to read whats currently in any sector.
> No problems there.
>
> Now I need to call our script from C.
>
> I want to copy each of the bytes within the sector into an C unsigned
char *array
Without knowing the C API, I would try to generate byte string from within
Python. Three possibilities:
1. turn list into string - secstring = ''.join(map(chr, seclist)). Then
use C API to get the cstring from string object.
2. turn list/tuple into array (of unsigned chars) or built that directly
instead of list or tuple. See array module. I presume you can get at the
buffer itself from C API.
3. look into ctypes module.
> Is there any way to do this using Py_ParseTuple or Py_Parse ???
If you mean PyArg.... stuff, I believe these are meant for parsing
argu;ments passed as heterogeneous Python tuple, which is quite different
from what you want to do.
Terry J. Reedy
More information about the Python-list
mailing list