473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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 1901
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Torsten Mohr | last post by:
Hi, i write a set of extension modules for python in C. I also use some new types that i defined there. At the moment i write some methods that expect some of these types as parameters. I...
1
by: Torsten Mohr | last post by:
Hi, i write an extension module in C at the moment. I want to define some constants (integer mainly, but maybe also some strings). How do i do that best within this extension module in C? ...
3
by: Markus Wintermann | last post by:
hello, i try to write an extension which calls an api. however, i haven´t written very much till now, but i`ve already managed to make a mistake. because when i try to call my function,...
0
by: Sam L. | last post by:
I am trying this out, parts of it are direct from the Python 2.4 manual. //----------- icallbk.c #include "Python.h" PyObject *fcallback = NULL; static PyObject* call_func(PyObject* self,...
6
by: Java and Swing | last post by:
Hi, I have been posting about writing a C extension for Python...so far, so good. At least for the "simple" functions that I need to wrap. Ok, my c function looks like... MY_NUM...
4
by: Luke Miller | last post by:
Hello, I am working on my first python module based on a c program. The module builds and installs OK using dist-utils, and imports fine into python. However, when I try and use the one wrapper...
0
by: Alexander Eisenhuth | last post by:
Hello Together, Shortly what I'm doing: - Extending python with boost.pthon extension - Using python C-Api for datatypes in the extension - extension has a thread (that can be stopped/started)...
5
by: pythoncurious | last post by:
Hi, I'm having a bit of trouble when writing a python extension. I can't seem to figure out what I did wrong. I tried to make a minimal example, but it's still quite a bit of code. It would be...
0
by: John Vines (CISD/HPCD) | last post by:
All, I am trying to create an extension module and keep getting an error, "/usr/local/lib/python2.5/site-packages/mytest.so: undefined symbol: PyInitModule" thanks in advance, *Here is my...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.