推荐学习书目
› 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 · Dec 13, 2016 · 3015 views
    This topic created in 3578 days ago, the information mentioned may be changed or developed.
    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 replies  •  2016-12-13 23:44:20 +08:00
    zycode
        1
    zycode  
    OP
       Dec 13, 2016
    解决了,把 POINT 也用导出就行了.不过这样感觉一旦用到复杂一点的结构还真是累人
    justou
        2
    justou  
       Dec 13, 2016
    可以试试 cython, 更容易维护, 几乎照抄 C/C++头文件, 也有一些自动化工具, 从 .h 直接生成 .pxd

    http://docs.cython.org/en/latest/
    zycode
        3
    zycode  
    OP
       Dec 13, 2016
    @justou 好的,多谢,回头我去看看去,又碰到 boost python 参数引用和指针 怎么声明的问题了,头大。帮助文档也没找到详细解释。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2604 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:56 · PVG 21:56 · LAX 06:56 · JFK 09:56
    ♥ Do have faith in what you're doing.