[C++-sig] Creating a python class from c++

James Healey healeyjames at yahoo.co.uk
Fri Nov 17 23:26:47 CET 2006


Ok lets take boost away from what im trying to do, and
try to achieve the same thing with just python.

Here's my .py file:

class MyTest:
	def TestFunc():
		print "Hello From MyTest.TestFunc"

And here's my code to handle all this so far:
	Py_Initialize();
	PyObject *pMainModule = PyImport_AddModule(
"__main__" );
	PyObject *pDict = PyModule_GetDict( pMainModule );

	std::string *pythonScript = readPythonScript(
"Game.py" );
	if( pythonScript != NULL )
	{
		PyRun_String( pythonScript->c_str(), Py_file_input,
pDict, pDict );
		delete pythonScript;
	}

	PyObject* test = PyDict_GetItemString(	pDict,
"MyTest");


And this is as far as I have got.

Any help you can give would be great.

Send instant messages to your online friends http://uk.messenger.yahoo.com 



More information about the Cplusplus-sig mailing list