Jeff Holle <jeff.holle@verizon.net> writes:
Dave wrote:
Why struggle? This should be:
object /* Returns a borrowed reference */ getPythonFunction(string moduleName,string functionName) { object _module(handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())))); <<-- line 63 in Main.cpp
return _module.attr(functionName.c_str()); }
------------------------------------------------------------------------
Always a good question. The code doesn't compile as presented.
Oh, it should; GCC bug it looks like. object getPythonFunction(string moduleName,string functionName) { object _module = object( handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())) ) ); return _module.attr(functionName.c_str()); } or object getPythonFunction(string moduleName,string functionName) { object _module(( handle<>( PyImport_ImportModule(const_cast<char*>(moduleName.c_str())) ) )); return _module.attr(functionName.c_str()); } works.
An underlining concern I have is error handling. When PyImport_ImportModule fails, a NULL pointer is returned. Seems like the underlining machinery in "handle<>" is intolerant of this.
What makes you say that? -- Dave Abrahams Boost Consulting http://www.boost-consulting.com