From 5645ee2a3fe8c404ced345da45de814f8c1ae271 Mon Sep 17 00:00:00 2001 From: Kelvin Rodriguez Date: Fri, 14 Dec 2018 12:07:51 -0700 Subject: [PATCH] removed function from notebook to use the one in ale --- notebooks/cpp_load.ipynb | 59 ---------------------------------------- 1 file changed, 59 deletions(-) diff --git a/notebooks/cpp_load.ipynb b/notebooks/cpp_load.ipynb index 66040ad..3914bc1 100644 --- a/notebooks/cpp_load.ipynb +++ b/notebooks/cpp_load.ipynb @@ -117,65 +117,6 @@ " \"END\\n\";\n" ] }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [], - "source": [ - "std::string load(std::string filename) {\n", - " static bool first_run = true;\n", - " if(first_run) {\n", - " // Initialize the Python interpreter but only once.\n", - " first_run = !first_run;\n", - " Py_Initialize();\n", - " atexit(Py_Finalize);\n", - " }\n", - " \n", - " // Import the file as a Python module.\n", - " PyObject *pModule = PyImport_Import(PyUnicode_FromString(\"ale\"));\n", - "\n", - " // Create a dictionary for the contents of the module.\n", - " PyObject *pDict = PyModule_GetDict(pModule);\n", - "\n", - " // Get the add method from the dictionary.\n", - " PyObject *pFunc = PyDict_GetItemString(pDict, \"loads\");\n", - "\n", - " // Create a Python tuple to hold the arguments to the method.\n", - " PyObject *pArgs = PyTuple_New(1);\n", - "\n", - " // Set the Python int as the first and second arguments to the method.\n", - " PyObject *pString = PyUnicode_FromString(filename.c_str());\n", - " PyTuple_SetItem(pArgs, 0, pString);\n", - "\n", - " // Call the function with the arguments.\n", - " PyObject* pResult = PyObject_CallObject(pFunc, pArgs);\n", - "\n", - " // Print a message if calling the method failed.\n", - " if(pResult == NULL) {\n", - " throw \"pResult\";\n", - " }\n", - "\n", - " std::string cResult;\n", - "\n", - " PyObject *temp_bytes = PyUnicode_AsUTF8String(pResult); // Owned reference\n", - " if (temp_bytes != NULL) {\n", - " char *temp_str = PyBytes_AS_STRING(temp_bytes); // Borrowed pointer\n", - " cResult = temp_str; // copy into std::string\n", - " Py_DECREF(temp_str); \n", - " } else {\n", - " throw \"pybytes\";\n", - " }\n", - " \n", - " Py_DECREF(temp_bytes);\n", - " Py_DECREF(pArgs);\n", - " Py_DECREF(pModule);\n", - " Py_DECREF(pString);\n", - " \n", - " return cResult;\n", - "}" - ] - }, { "cell_type": "code", "execution_count": 4, -- GitLab