C API: how to replace python number object in place?

Stephen Vavasis vavasis at cpu111.math.uwaterloo.ca
Fri May 15 05:24:51 CEST 2009


In my previous posting, I inquired how to change a python numeric object 
in place.  Several people responded that this is not possible.  Perhaps I 
should explain the larger problem that I am trying to solve, and then the 
solution will become apparent.  I have a C routine R that invokes a Python 
routine S repeatedly.  This Python routine S takes three arguments, two 
floats and an integer.  I have read the documentation explaining how R can 
use the C API to construct an argument list for invoking S.  The issue 
that baffles me is that, as far as I can tell, each time R invokes S 
again, it needs to deallocate and reallocate the three arguments.  It 
would seem be much more efficient if R could create the argument list once 
and then modify the values inside of it for each subsequent invocation of 
S.

-- Steve Vavasis


In article <JrudnVSRisF_5pHXnZ2dnUVZ_rOdnZ2d at pdx.net>,
Scott David Daniels  <Scott.Daniels at Acm.Org> wrote:

>If you do figurte out how to do what you want, you will put us in the
>old FORTRAN trap:  People can write code that changes the value of a
>constant.
>The code:
>     month = 12 # make it december
>     inches_per_foot = 12
>     make_previous(month)
>     print ('Month is now: %s, inches_per_foot = %s' % (
>                month, inches_per_foot))
>might print:
>     Month is now: 11, inches_per_foot = 11
>
>--Scott David Daniels
>Scott.Daniels at Acm.Org





More information about the Python-list mailing list