Set PyObject value from C extension

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Tue Jun 12 00:08:46 EDT 2007


En Tue, 12 Jun 2007 00:09:30 -0300, Allen <Allen.Chenal at gmail.com>  
escribió:

> I have the PyObject pointers, and want to set different type of values
> to them.
>
> For example,
>
> INT8 nValue1 = 0;
> INT16 nValue2 = 1;
> FLOAT32 fValue = 1.0f;
>
> PyObject* var1 <= nValue1
> PyObject* var2 <= nValue2
> PyObject* var3 <= nValue3
>
> How to do it?

What do you mean by "I have the PyObject pointers"? Integers and floats  
are immutable in Python. You can't "set" an existing PyIntObject or  
PyFloatObject to another value. But you can create *new* objects from the  
desired values, using PyInt_FromLong and PyFloat_FromDouble.

If this is your first approach to Python, I suggest first become familiar  
with the language, and later try to mix it with C code.

-- 
Gabriel Genellina




More information about the Python-list mailing list