meine Frage bezieht sich diesmal stark auf Py_BuildValue.
Ist es irgendwie möglich drei 1D-Array oder ein 2D-Array aus C mit, vor Laufzeit, unbekannter Länge, an Python zu übergeben?
(Also Y-Dimension wäre bei den 2D-Array dann natürlich 3; die X-Dimension wäre auch immer gleich lang)
meine bisherige Lösung gefällt mir gar nicht, bzw. geht auch nur mit fester Länge:
Das C-Programm:
Code: Alles auswählen
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "python2.7/Python.h"
int main()
{
	srand(time(NULL));
	int i;
	
	int a[5], b[5], c[5];
	
	for(i=0; i < 5; i++)
	{
		a[i] = rand() % 10+10;	//10-19
		b[i] = rand() % 5+5;	//5-9
		c[i] = rand() % 5;		//-4
		printf("%d  ", a[i]);
		printf("%d  ", b[i]);
		printf("%d\n", c[i]);
	}
	
	Py_Initialize();
	PyObject *modul, *funk, *ret, *zahl;
	
	PySys_SetPath(".");
	modul = PyImport_ImportModule("script2"); 
	
	if(modul)
	{
		funk = PyObject_GetAttrString(modul, "ausgabe");
		
		//Werte einzeln übergebn...
		zahl = Py_BuildValue("(iiiii iiiii iiiii)",a[0], a[1], a[2], a[3], a[4],
			   b[0], b[1], b[2], b[3], b[4],
			   c[0], c[1], c[2], c[3], c[4]);
		ret = PyObject_CallObject(funk, zahl);
		Py_DECREF(zahl);	
		Py_DECREF(ret);	
		Py_DECREF(funk);
		Py_DECREF(modul);			
	}
	else
		printf("Fehler: Modul nicht gefunden\n");
	
	return 0;
}Code: Alles auswählen
def ausgabe(a0, a1, a2, a3, a4, b0, b1, b2, b3, b4, c0, c1, c2, c3, c4):
	print "a = [", a0, ", ", a1, ", ", a2,  ", ", a3,  ", ", a4, "]"
	print "b = [", b0, ", ", b1, ", ", b2,  ", ", b3,  ", ", b4, "]"
	print "c = [", c0, ", ", c1, ", ", c2,  ", ", c3,  ", ", c4, "]"
