Set PyObject value from C extension

A

Allen

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?

Regards,
Allen Chen
 
G

Gabriel Genellina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top