469,934 Members | 2,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Set PyObject value from C extension

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

Jun 12 '07 #1
1 1762
En Tue, 12 Jun 2007 00:09:30 -0300, Allen <Al**********@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

Jun 12 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Torsten Mohr | last post: by
3 posts views Thread by Markus Wintermann | last post: by
reply views Thread by Sam L. | last post: by
6 posts views Thread by Java and Swing | last post: by
4 posts views Thread by Luke Miller | last post: by
reply views Thread by Alexander Eisenhuth | last post: by
5 posts views Thread by pythoncurious | last post: by
reply views Thread by John Vines (CISD/HPCD) | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.