Re: C API: how to replace python number object in place?
- From: Benjamin Peterson <benjamin@xxxxxxxxxx>
- Date: Thu, 14 May 2009 18:47:40 +0000 (UTC)
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...
.
- References:
- C API: how to replace python number object in place?
- From: Stephen Vavasis
- C API: how to replace python number object in place?
- Prev by Date: Re: putting date strings in order
- Next by Date: Re: How to get all named args in a dict?
- Previous by thread: C API: how to replace python number object in place?
- Next by thread: Re: C API: how to replace python number object in place?
- Index(es):
Relevant Pages
|