Re: Question concerning array.array and C++
- From: Hrvoje Niksic <hniksic@xxxxxxxxxx>
- Date: Wed, 05 Nov 2008 16:24:27 +0100
[ 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 <Auslieferator@xxxxxxx> writes:
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
.
- References:
- Question concerning array.array and C++
- From: Fabio
- Question concerning array.array and C++
- Prev by Date: Re: False and 0 in the same dictionary
- Next by Date: Re: Parse each line by character location
- Previous by thread: Question concerning array.array and C++
- Next by thread: Re: Can I build Python with lthread instead of pthread?
- Index(es):