Re: parsing a tuple in embedded python



Thanks Fredrik. Yes, I see now how the function works. I'm new to
Python and the book I'm studying out of wasn't too explicit in how to
handle arrays. I've changed the code to what you suggested, but
strangely enough nothing got read into my array. If I return a single
integer from my Python method, I get the expected return using:
PyArg_Parse(return, "i", &integer);
But,
PyArg_Parse(return, "(iii)", array, array+1, array+2)
and
PyArg_Parse(return, "(iii)", &array[0], &array[1], &array[2])
does not alter "array" at all. Any ideas? Thanks



Fredrik Lundh wrote:
> jenkins.justin@xxxxxxxxx wrote:
>
> > I am returning a tuple from my python method and am stuck trying to
> > figure out how to read it into a C array using PyArg_Parse.
> > My C Code:
> > int array[3];
> > PyArg_Parse(return, "(iii)", &array);
> >
> > My Python Code:
> > mytuple = (1,2,3)
> > return mytuple
> >
> > That gives me a segmentation fault. What am I doing wrong?
>
> you're not providing enough arguments; "iii" means three pointers, not
> one. try:
>
> PyArg_Parse(return, "(iii)", array, array+1, array+2)
>
> instead. or, if you prefer maximum clarity:
>
> PyArg_Parse(return, "(iii)", &array[0], &array[1], &array[2])
>
> (I assume you left out the error handling code; ignoring the return value
> from PyArg_Parse is not a good idea)
>
> </F>

.



Relevant Pages

  • (patch for Bash) regex(3) splitting/matching
    ... I usually do this in Python. ... 'help array' will give you more info on other options for 'array' ... int dollarflag, zeropad, compareflag; ... SHELL_VAR *var; ...
    (comp.unix.shell)
  • Re: Why C Is Not My Favourite Programming Language
    ... And the number of modules in Python 2.4's Global Module Index is 362. ... The PDP architecture ideals ... fflushcan't be used to flush the contents of standard ... But it's not foolish that in ksh if you refer to an array name ...
    (comp.lang.c)
  • Re: Allowing zero-dimensional subscripts
    ... The items of a tuple are arbitrary Python objects. ... items are formed by comma-separated lists of expressions. ... the grammar rule used for list subscript is different from the ... an array with n-dimensions of length 3 would have ...
    (comp.lang.python)
  • Re: Brain going crazy with recursive functions
    ... I want eventually to port this to scheme, but I know python ... I'm in linear_search for the array, I also call linear_search for each ... return linear_search_iter(0, truth_func, array, acc) ...
    (comp.lang.python)
  • RE: Assignment to slice
    ... minutes of python experience. ... > the array, i.e. insist on: ... Python doesn't like that I'm assigning ... > to a slice, over non-existent array indexes, sets ...
    (comp.lang.python)