通过boost python从python中提取常量值
Extract constant value from python by boost python
python代码
import ldap,ldif
l = ldap.initialize('ldaps://RIO-PC:636')
l.set_option(ldap.OPT_TIMEOUT);
我想提取ldap的常数值。OPT_TIMEOUT,但是如何呢?
#include <iostream>
#include <boost/python.hpp>
int main()
{
namespace bp = boost::python;
try{
Py_Initialize();
bp::object main_module = bp::import("__main__");
bp::import("ldap");
bp::import("ldif");
bp::object main_namespace = main_module.attr("__dict__");
bp::exec("import ldap,ldifn"
"l = ldap.initialize('ldaps://RIO-PC')n",
main_namespace);
boost::python::object ldap = boost::python::extract<boost::python::object>(main_namespace["l"]);
ldap.attr("OPT_TIMEOUT"); //this line will throw exception
}catch(boost::python::error_already_set const &){
PyErr_Print();
PyErr_Clear();
}
}
错误信息是
AttributeError: SimpleLDAPObject没有属性'OPT_TIMEOUT'
环境编译器:vc2008Boost版本:1.55_0操作系统:win7 64bits(x64)
您的c++代码试图提取l.OPT_TIMEOUT
,而不是ldap.OPT_TIMEOUT
。试着
bp::object ldap_module = bp::import("ldap");
ldap_module.attr("OPT_TIMEOUT");
相关文章:
- #定义c-预处理器常量..我做错了什么
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- Pybind11:将元组列表从Python传递到C++
- 用C++中的一个变量定义一个常量
- 什么时候在C++中返回常量引用是个好主意
- 代理对象的常量正确性
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 如何在c++中使用引用实现类似python的行为
- 通过多个头文件使用常量变量
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 递归列出所有目录中的C++与Python与Ruby的性能
- 在cuda线程之间共享大量常量数据
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 是默认情况下分配给char数组常量的值
- 从python中调用C++函数并获取返回值
- Python 3.7 和 excess_args 的 SWIG 问题
- 私有类型的静态常量成员
- Swig:如何类型映射c ++字符串常量和python字符串?