473,398 Members | 2,380 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,398 software developers and data experts.

Question concerning array.array and C++

Hi All,
I have a question concerning the use of array.array inside of C++ code I
wrote.

I am working with _big_ data files but some entries in these files are
usually bounded say between -5 to 40. Returning a Python list makes no
sense. In Python I always work with the array.array module which does
the trick. But now that I wrote my own C++ module for some preprocessing
I need the return array.array objects.

Consider the object

array.array('c',[40,40,40])

Can I create such an object from within the C++ layer and pass it to the
Python layer?

I already looked at arraymodule.c and tried to link the arraymodule.o
file to my code but then I have to mess around with extern "C" and the
like and it gets really messy.

Any help would be great!

Fabio

Nov 5 '08 #1
1 2286
[ Please consider posting to the capi-sig list, which is dedicated to
answering questions like yours.
http://mail.python.org/mailman/listinfo/capi-sig ]

Fabio <Au***********@gmx.netwrites:
Consider the object

array.array('c',[40,40,40])

Can I create such an object from within the C++ layer and pass it to
the Python layer?
Yes, simply access the array type object using getattr (the "."
operator), much like you would from Python, and instantiate the type
by calling it:

// import array
PyObject *array_module = PyImport_ImportModule("array");
if (!array_module)
goto error;

// array_type = array.array
PyObject *array_type = PyObject_GetAttrString(array_module, "array");
Py_DECREF(array_module);
if (!array_type)
goto error;

// array = array_type('c', [40, 40, 40])
PyObject *array = PyObject_CallFunction(array_type, "c[iii]", 'c', 40, 40, 40);
if (!array)
goto error;

// at this point you have (a new reference to) the array object
Nov 5 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Max | last post by:
Hi, I'm a perl programmer and am trying to learn PHP. So far I have figured out most of the differences, but have not been able to find out how to do the following: When running through a...
0
by: AMDIRT | last post by:
I have a few questions about IssueVision (from WindowsForms) concerning its scalability and performance. Rather, if I were to implement techniques described here into another application, how...
2
by: Oly | last post by:
give your opinions concerning our site,end work first year web technology www.zwin.tk in java: -navigation -stylechanger (with cookie) -pamorama -gallery
3
by: Jesika | last post by:
Hi, I have a cumbersome question: Given the following declaration: string varray = new string; (15 blocks of memory) Does it allocate a contiguous blocks of memory or not? If it does, is...
4
by: Rainer Queck | last post by:
Hi NG I have some questions concerning BitArrays. Assumption : BitArray with 16 Bits Is it possible to "load" a BitArray with a UInt16 Value with out iterating it like: UInt16 Bits =...
2
by: adamizer | last post by:
okay i try to compile this simple code in Dev C++ and i get some serious errorage #include <iostream> using namespace std; int main() { char array = {{'a','b','c','d','e'},
9
by: Thomas Ploch | last post by:
Hello fellow pythonists, I have a question concerning posting code on this list. I want to post source code of a module, which is a homework for university (yes yes, I know, please read...
1
by: Patrick | last post by:
Hi I have a basic question concerning rotations and bitmasking. Assume the following code fragement. uint32 p_lo = { 0x00, 0x00}; for (j = 0; j < 64; j++ )
10
by: Roman Zeilinger | last post by:
Hi I have a beginner question concerning fscanf. First I had a text file which just contained some hex numbers: 0C100012 0C100012 ....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.