calling python function from C++ using call
Hi, I'm trying to call the function `array' (from the python module numarray.strings) from inside C++ code. This function initializes a character array. It has the arguments array(buffer=None, itemsize=None, shape=None, byteoffset=0, bytestride=None, kind=CharArray) I'm doing this as follows: The C++ end looks like **************************************************************** bcallback.cc **************************************************************** ... object charr(PyObject* func, list buf, object itemsize, tuple sh) { return boost::python::call<object>(func, buf, itemsize, sh); } ... **************************************************************** and the Python end looks like **************************************************************** callback.py **************************************************************** from bcallback import charr import numarray.strings as numstrings def retcharr(buffer, sh): return charr(numstrings.array, buffer, None, sh) **************************************************************** This actually works. Namely: In [2]: import callback In [3]: callback.retcharr(['a', 'c', 'a', 'c', 'a', 'c', 'g', 't', 'g','t','g','t'], (6,2)) Out[3]: CharArray([['a', 'c'], ['a', 'c'], ['a', 'c'], ['g', 't'], ['g', 't'], ['g', 't']]) However, I'm wondering if this is the best way of proceeding, or if there is a better way. Thanks in advance for comments. Faheem.
On Sun, 27 Jun 2004 06:17:51 +0000 (UTC), Faheem Mitha <faheem@email.unc.edu> wrote:
Hi,
I'm trying to call the function `array' (from the python module numarray.strings) from inside C++ code. This function initializes a character array. It has the arguments
Actually, I do now have a question. I realised that it would be better if the C++ code could call the array function directly. This would involve embedding the interpreter, right? I'd appreciate a confirmation of this. I.e. I'd need to do something equivalent to from numarray.strings import array in the C++ code. I'll try to figure out how to do this from the tutorial and the reference manual, but it would be much appreciated if som kind person would just tell me what the syntax should look like for importing. :-) Pretty please? Faheem.
participants (1)
-
Faheem Mitha