467,161 Members | 940 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,161 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
  • viewed: 1698
Share:
1 Reply
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@gmail.com | 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.