Embedding Python into C/C++ applications
Hi Could somebody, please tell me where I can find information about embedding Python into a C/C++ application. The example in the docs is rather simple. I am looking for something a bit more complex and longer -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Python V2.4.2 source code
Hi Does anybody know from where I can get a copy of the source for Python V2.4.2. I downloaded what is reckoned to be the source code from www.python.org, but is turns out to be the MacXOS version with the core modules missing. The reason I am looking for the source code is so I can make a debug build -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python V2.4.2 source code
Hi That particular file doesn't include the implementation files for the core modules. The platform specific directories only include two or three files. Only the Mac directory contains any C code files -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python V2.4.2 source code
Hi I downloaded what I thought was the source code from http://www.python.org/2.4.2/python-2.4.2.tgz -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Re: Python V2.4.2 source code
Hi Thank you very much. It seems the version tar that is embedded in WinRAR is broken. It gets as far as the Mac directory and then bombs out. The version of tar that is bundled with CygWin worked just fine -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Embedded Python
Hi Is it possible to execute a whole script using the C API function PyRun_String? At moment I load the script into a buffer. Then I get each line of the script and pass it PyRun_String. This seems very inefficient. It would be more efficient if I could pass the complete string buffer to PyRun_String and execute the script as a whole -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Problem with C-API
Hi I spent the whole of yesterday trying the get the following C code to execute PyRun_String("def title();", Py_file_input, dict, dict); PyRun_String("\treturn 'Foo Bar'", Py_file_input, dict, dict); PyRun_String("x = title()", Py_file_input, dict, dict); PyObject * result = PyRun_String("print x", Py_file_input, dict, dict); printf( "The result is %s\n", PyObject_AsString( result ); Each line throws an error. Could somebody tell what is wrong with the above code. Here below is the output from my test app Starting Test .. The file "testtitle" is open for reading The variable codeStrings contains Line 0 def title() Line 1 return "Foo Bar" The variable scriptText contains def title() return "Foo Bar" The variable tempList contains Line 0 testtitle Line 1 title Module Name is testtitle Function Name is title The variable functionCode contains def title() return "Foo Bar" Python initialized successfully Module object successfully created Dict object successfully created Failed to create a Result object. The title of the this task is -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with C-API
Hi Duncan Your version of the app works apart from this part else { PyObject *rString = PyObject_Str(result); if (rString==NULL) { Py_DECREF(result); PyErr_Print(); return; } printf( "The result is %s\n", PyString_AsString(rString)); Py_DECREF(rString); Py_DECREF(result); } } The result of the printf state is: "The result is None" result = PyRun_String("print x", Py_file_input, dict, dict); The above line of code displays the value returned from the title() function. My problem is I need to be able to cature the return value because in the real application it will be displayed in a Process Log Widget. Also the real scripts will be much longer. I have not had a problem writing Python extensions, but when it comes to embedded Python I just see how to get my code to work. Any further help would be greatly appreciated -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with C-API
Hi Duncan's example worked to a point. The line PyRun_String( "print x", Py_file_input, dict, dict); print out the contents of x, but I don't want to print x out. I want to be able to grab whateven the variable x contains so that I can pass it on for further processing by the C++ application. BTW this is only a test case. The real scripts are much bigger. I must say the documentation is not of much help and there are no books or articles covering embedding Python in any detail. What there is is very much out of date. -- Best Regards John -- http://mail.python.org/mailman/listinfo/python-list