2006年04月25日 星期二 14:16
我自己从网上下了些代码,然后自己写了几个函数,但运行时却出现 TypeError: unbound method Boost.Python.function object must be called with Out instance as first argument (got str instance instead) 请问各位高手这是怎么回事,我的源代码如下, class pyRead{ public: dict *mpDictionary; object Interface; pyRead(void); ~pyRead() ; object pyGetInterFace(); void pyReadFile(const char* filepath, const char* filename); int CallPython(const char *commandtext, const char *errortext); }; class pyOut{ public: void myOut(std::string const& str) { cout<< ("Out",no_init) .def ("myOut",&pyOut;::myOut ) ; return interfaces; } pyRead::pyRead(void) { Py_Initialize(); Interface = pyGetInterFace(); mpDictionary = new dict(handle (borrowed(PyDict_New()))); PyDict_SetItemString(mpDictionary->ptr(), "__builtins__", PyEval_GetBuiltins()); PyDict_SetItemString(mpDictionary->ptr(), "Files", Interface.ptr()); } int pyRead::CallPython(const char *commandtext, const char *errortext) { try { handle ( PyRun_String(commandtext , Py_file_input, mpDictionary->ptr(), mpDictionary->ptr()) ); return 0; } catch (error_already_set) { PyErr_Print(); return 1; } } void pyRead::pyReadFile (const char* filepath, const char* filename) { char cmdText[512]; char errText[512]; sprintf(cmdText, "from %s import *\n",filename); sprintf(errText, "Error importing file: %s\n", filepath); int errorCode = CallPython(cmdText, errText); if (errorCode != 0) return; errorCode = CallPython("outtest(Files)\n", "Error with outttest method\n"); return ; } pyRead::~pyRead() { if (mpDictionary != NULL) delete mpDictionary; Py_Finalize(); } void main() { char *name("Test"); char *path("D:\\Study\\Temp\\py4\\py4\\Debug"); pyRead pyTemp; pyTemp.pyReadFile (path, name); return ; } -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060425/eaa55900/attachment.html
Zeuux © 2025
京ICP备05028076号