[C++-sig] Accessing C++ values from within Python

xin xin at xlevus.net
Thu Jul 1 08:41:51 CEST 2004


Hi.
I have a setup such as the following:

class object {
public:
	void doSomthingElse();
	float x;
	float *y;
	Somthing SomePyScript;
};

int main()
{
	object *array = new object[10]; // size of array is only an example
	for (int i = 0; i < 10; i++)
	{
		array[i].y = new float[array[i]]
		RunPythonScript(array[i]);
	}
	return 1;
}

Where:
  - " Somting SomePyScript; " Is some reference to a python script that is 
affiliated with this instance of the class (varies from instance to instance)
  - " RunPythonScript(array[i]); " Is some method of running the python script 
that is affiliated with the instance array[i].

My intention is that the python scripts change values within the class 'object'
e.g. The python code sets 'x' to equal 0.9. And then sets each value of y to 
equal a muliple of 9. (y[0] = 0, y[1] = 9, y[2] = 18, ... ,y[100] = 900 etc...)

Is this at all possible? Is it possible without moving all the memory from one 
place, to another area accessable by both python and then back again? If so how 
would I go about doing it?

I've tried all sorts of methods of attempting this, but have had no luck. Any 
help would be appreciated.

Thanks.





More information about the Cplusplus-sig mailing list