title: Calling sympy using C++ embedding
body: <p>I am trying to use sympy with my c++ program and am using the following embedding code to do that. </p>
  
  <pre><code>int sym_ex(const char * input_expression, const char * output_expression){
  
      PyObject *pName, *pModule, *pDict, *pFunc;
      PyObject *pArgs, *pValue;
      int i;
  
      const char * file = "sympy";
      const char * function = "simplify";
  
  
      Py_Initialize();
      //PyRun_SimpleString("from sympy import *\n");
      pName = PyString_FromString(file);
      /* Error checking of pName left out */
  
      pModule = PyImport_Import(pName);
      Py_DECREF(pName);
  
      if (pModule != NULL) {
          pFunc = PyObject_GetAttrString(pModule, function);
          /* pFunc is a new reference */
  
          if (pFunc &amp;&amp; PyCallable_Check(pFunc)) {
  
              pArgs = PyTuple_New(1);
              pValue = PyString_FromString(input_expression);
              printf("the string passed %s\n", input_expression);
              if (!pValue) {
                  Py_DECREF(pArgs);
                  Py_DECREF(pModule);
                  fprintf(stderr, "Cannot convert argument\n");
                  return 1;
              }
              /* pValue reference stolen here: */
              PyTuple_SetItem(pArgs, 0, pValue);
  
              pValue = PyObject_CallObject(pFunc, pArgs);
              Py_DECREF(pArgs);
              if (pValue != NULL) {
                  printf("Result of call: %s\n", PyString_AsString(pValue));
                  Py_DECREF(pValue);
              }
              else {
                  Py_DECREF(pFunc);
                  Py_DECREF(pModule);
                  PyErr_Print();
                  fprintf(stderr, "Call failed\n");
                  return 1;
              }
          }
          else {
              if (PyErr_Occurred())
                  PyErr_Print();
              fprintf(stderr, "Cannot find function \"%s\"\n", function);
          }
          Py_XDECREF(pFunc);
          Py_DECREF(pModule);
      }
      else {
          PyErr_Print();
          fprintf(stderr, "Failed to load \"%s\"\n", file);
          return 1;
      }
      Py_Finalize();
      return 0;
  
  }
  </code></pre>
  
  <p>But, when I write a small program using this function and run it,</p>
  
  <pre><code>#include &lt;stdio&gt;
  #include &lt;iostream&gt;
  
  int main(){
  
  char * input_expression = "2 + 2";
  char * output_expression = new char[250];
  
  sym_ex(input_expression, output_expression);
  
  return 0;
  }
  </code></pre>
  
  <p>It gives out the following type error. I am running on windows in Visual C++, Python 2.7.8</p>
  
  <pre><code> Exception TypeError: 'expected string or Unicode object, Integer found' in &lt;module 'threading' from 'C:\Python278\Lib\threading.pyc'&gt; ignored
  </code></pre>
  
  <p>Can somebody help me? Thanks</p>