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



Stephen Vavasis <vavasis <at> cpu111.math.uwaterloo.ca> writes:


If x is a C variable of type PyObject*, and I happen to know already that
the object is of a numeric type, say int, is there a way to change the
value of x in place to a different number? In the C/API documentation I
found routines to increment or decrement it in place, but I didn't find a
routine to simply replace its value by a different value. (I suppose I
could change it to the new value via an increment or decrement, but this
is ugly as well as being susceptible to overflow problems and roundoff
errors in the case of floats.)

Even in the C-API, Python ints and longs are immutable. You can convert it to a
C int and work with it, otherwise you have to use the APIs which create new
objects: PyNumber_Add etc...



.



Relevant Pages

  • Re: How can I increment an integer one-at-a-time?
    ... int i = 0; ... trint wrote: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C API: how to replace python number object in place?
    ... that the object is of a numeric type, say int, is there a way to ... Which routines to increment or decrement the number are you referring ...
    (comp.lang.python)
  • RE: Robby, __int8 limited to: -128 to 127.
    ... And yes an 8bit int cannot hold a value of 256. ... //MIDSB OF MESSAGE ADDRESS IN PAR FLASH ... In order to access the data from my external memory I need a three byte ... and increment the A0 value from 1 to 2. ...
    (microsoft.public.vc.language)
  • Writing Classes
    ... Clock application ... private int hr; //store hours ... public void setTime{ ... //Method to increment the time by one second ...
    (comp.lang.java.programmer)
  • Re: Definition of expression and statement.
    ... The fact that a while loop is recognized ... behavior, e.g., if a is an "int" variable and is initially set to ... The various modifier operators, ... increment and decrement, have TWO uses: ...
    (comp.lang.c)