Using The Python/c Api To Get The Values Of Pystrings In The Interpreter As Cstrings Within A C Program
I've been messing around with the Python/C API and have this code: #include #include #include int main(int argc, char *argv[]) {
Solution 1:
You need to use PyString_AsString. I think it goes something like this:
PyObject* module = PyImport_AddModule("__main__");
PyObject* o = PyObject_GetAttrString(module , "__NAME__");
if (PyString_Check(o))
{
const char* name = PyString_AsString(o);
// don't delete or modify "name"!
}
Py_DECREF(o);
Post a Comment for "Using The Python/c Api To Get The Values Of Pystrings In The Interpreter As Cstrings Within A C Program"