title: How to convert PyObjects to C data types?
body: <p>I am working on a project where I have to convert a user input C++ string variable to python executable code, I'm using the Python C API, so I have to go through the intermediary of converting the C++ string to a C string (or character array). Once I get there, I can't get the value to print once the code has been run. I'm searching for what the proper function in the Python C API is. I've tried <code>PyString_AsString(),</code> <code>PyBytes_AsString(),</code> and <code>PyObject_AsUTF8String</code>so far. Each of these functions has caused a memory issue when I try and run it with the code below. I've had to hard reboot my system with these three.</p>
  
  <pre><code>    Py_Initialize();
  //the expected output, the player's output, and the compare functions
  //PyObject* expectAnswer; //the expected answer for the level
  PyObject* main = PyImport_AddModule("_main_");
  PyObject* globalDictionary = PyModule_GetDict(main);
  PyObject* localDictionary = PyDict_New();
  PyObject* result = PyRun_String(cPlayerString, Py_file_input, globalDictionary, localDictionary);
  
  
  
  Py_Finalize();
  </code></pre>
  
  <p>I am wondering whether I'm just not using the right call. <code>const char* PyUnicode_AsData()</code> looks promising, but I still have no idea whether I'd need to convert what I have into Unicode first. </p>
  
  <p>Thanks for all the help!</p>