#include <iostream>
#include <string>
#include "Python.h"
using namespace std;

#define py PyRun_SimpleString(pythonCommand.c_str())

int main()
{
	string pythonCommand;

	//Python started
	Py_Initialize();
		
		pythonCommand = "import sys";py;
		pythonCommand = "from math import sqrt";py;
		pythonCommand = "sys.setrecursionlimit(1000000)";py;
			//factorial function
		pythonCommand = "def ft(x): return(1 if x==0 else x * ft(x-1))";py;
			//equation using function
		pythonCommand = "print(sqrt(((ft(2008) + ft(2009) + ft(2010))/(ft(2008)))))";py;

	//Python ended
	Py_Finalize();

	cin.get();
	return 0;
}

In the above code, everything works just fine. Now I want to expand on it. I want to take the number I get from Python and move it back into C++ and then manipulate it in C++. However, I'm not sure how to go about doing that, any ideas?

I tried outputting the string after ending the python, however, that just outputted the string itself, i.e. (print(xyz)) was all that was output by C++.

I hope its not illegal to bump this thread...

Seriously, does anyone have any idea how to do this? Should this maybe be posted in the Python forum?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.