boost.python,在python中调用c++接口注意的问题(python2.5.4)
2012-02-04 21:16
477 查看
1.
BOOST_PYTHON_MODULE(myClassModule)
{
class_<myClass>("myClass")
.def("setID", &myClass::setID)
.def("getID", &myClass::getID)
;
def("printTest", &printTest);
}
2.
Py_Initialize();
// PyRun_SimpleString("import sys");
// PyRun_SimpleString("sys.path.append('./')");
initmyClassModule(); //BOOST_PYTHON_MODULE这里面定义了
if (python::handle_exception(exec_mythma))
{
if (PyErr_Occurred())
{
BOOST_ERROR("Python Error detected");
PyErr_Print();
}
}
3.
python::object main = python::import("__main__");
python::object py_ = main.attr("__dict__");
python::object result = python::exec_file(
".\\myClassTest.py", py_, py_);
4.构造类时,带上module前缀
myObj = myClassModule.myClass()
5.boost.python编出来的dll改名字成pyd
python直接import dll名字
BOOST_PYTHON_MODULE(myClassModule)
{
class_<myClass>("myClass")
.def("setID", &myClass::setID)
.def("getID", &myClass::getID)
;
def("printTest", &printTest);
}
2.
Py_Initialize();
// PyRun_SimpleString("import sys");
// PyRun_SimpleString("sys.path.append('./')");
initmyClassModule(); //BOOST_PYTHON_MODULE这里面定义了
if (python::handle_exception(exec_mythma))
{
if (PyErr_Occurred())
{
BOOST_ERROR("Python Error detected");
PyErr_Print();
}
}
3.
python::object main = python::import("__main__");
python::object py_ = main.attr("__dict__");
python::object result = python::exec_file(
".\\myClassTest.py", py_, py_);
4.构造类时,带上module前缀
myObj = myClassModule.myClass()
5.boost.python编出来的dll改名字成pyd
python直接import dll名字
相关文章推荐
- 使用boost.python在python调用C++接口(windows)
- Python调用C/C++的接口(Boost)
- c++ 调用Python接口小问题
- c++调用python函数时,使用PyArray_SimpleNewFromData(nd, dims, typenum, data)函数时出现内存错误的问题
- 深入学习python (七) 如何用python调用C/C++接口
- python 调用dll中参数为BYTE的函数(注意接口定义的格式)
- c++调用python链接的问题及解决方法
- centos7下使用swig扩展python接口来调用c++ 实现声纹识别
- 嵌入式系统上C++调用C语言接口代码链接时找不到C函数问题处理
- 调用wx.request接口时需要注意的几个问题
- 【小程序】调用wx.request接口时需要注意的几个问题
- 如何在C++代码中调用python代码(MinGW+Boost.Python)
- Boost.Python实现C++与Python互调用
- 在C#里调用C++的dll时需要注意的一些问题<转>
- C++调用请求HTTP接口错误的问题
- Boost.Python实现C++与Python互调用
- PY++ 自动将你的C++程序接口封装供python调用
- c++调用python函数接口
- c++调用python封装接口
- C#调用C++版本dll时的类型转换需要注意的问题小结