[C++-sig] [boost::python] Unable to call a python object Member Function
shadow_dog1
shadowdog at sharkbyte.com
Fri Jul 18 16:59:22 CEST 2008
I hope someone can help with this boost::python question.
I create a python object and want to call a member function but it requires
the 'self' reference to be passed in?
Here is the python code:
class config:
def __init__(self, file):
self._config = file
def getfile(self, path):
return path + self._config
Here is c++ code:
#include <boost/python/object.hpp>
namespace python = boost::python;
int _tmain(int argc, _TCHAR* argv[])
{
Py_InitializeEx(0);
python::object configMod = python::import("config_wrapper");
python::object config = configMod.attr("my.config");
config("tgx.config");
python::object val = config.attr("getfile")("c:\datadir\");
Py_Finalize();
}
I get this exception when the code runs -
"TypeError: unbound method getfile() must be called with config instance as
first argument (got str instance instead)"
I have tried passing the 'config' instance a the first param but still get
the execption. The code works fine if i do not call a member function but
instead call a normal function?? I'm stuck...
--
View this message in context: http://www.nabble.com/-boost%3A%3Apython--Unable-to-call-a-python-object-Member-Function-tp18531200p18531200.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.
More information about the Cplusplus-sig
mailing list