V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zycode
V2EX  ›  Python

请教个 boost.python 的导出嵌套结构到 python 脚本中怎么访问的问题

  •  
  •   zycode · 2016-12-13 16:23:03 +08:00 · 1823 次点击
    这是一个创建于 2662 天前的主题,其中的信息可能已经有所发展或是发生改变。
    C++ 中有结构 B
    // POINT 为 GDI 的一个结构 struct POINT {int x,int y};
    struct B{
    POINT a1;
    int c;
    };

    用 boost.python 把 B 结构导出
    class_<B>("B")
    .def_readwrite("c",&B::c)
    .def_readwrite("a1",&B::a1)
    ;
    那么在 python 中怎么 对 a1.x 读写呢?直接操作 a1.x 会出错
    3 条回复    2016-12-13 23:44:20 +08:00
    zycode
        1
    zycode  
    OP
       2016-12-13 16:32:54 +08:00
    解决了,把 POINT 也用导出就行了.不过这样感觉一旦用到复杂一点的结构还真是累人
    justou
        2
    justou  
       2016-12-13 19:42:47 +08:00
    可以试试 cython, 更容易维护, 几乎照抄 C/C++头文件, 也有一些自动化工具, 从 .h 直接生成 .pxd

    http://docs.cython.org/en/latest/
    zycode
        3
    zycode  
    OP
       2016-12-13 23:44:20 +08:00
    @justou 好的,多谢,回头我去看看去,又碰到 boost python 参数引用和指针 怎么声明的问题了,头大。帮助文档也没找到详细解释。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5937 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 02:07 · PVG 10:07 · LAX 19:07 · JFK 22:07
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.