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
zhiqiang
V2EX  ›  Python

boost. Python 如何导出 c char array?

  •  
  •   zhiqiang · 2017-11-09 12:47:43 +08:00 · 1772 次点击
    这是一个创建于 2366 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题类似于 https://stackoverflow.com/questions/17885639/exposing-a-c-style-array-data-member-to-python-via-boost-python.

    直接用它的例子吧:

    struct S
    {
      char arr[4128];
    };
    
    void foo( S const * )
    {}
    
    BOOST_PYTHON_MODULE( test )
    {
      using namespace boost::python;
    
      class_<S>( "S" )
        .def_readwrite( "arr", &S::arr )
        ;
    
      def( "foo", foo );
    }
    

    这是编译会出错:

    error C2440: '=' : cannot convert from 'const char [4128]' to 'char [4128]'
    

    我不但想导出,而且想在 python 里直接当作一个 string 使用。有办法吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2178 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 02:16 · PVG 10:16 · LAX 19:16 · JFK 22:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.