推荐学习书目
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 · Nov 9, 2017 · 2293 views
    This topic created in 3131 days ago, the information mentioned may be changed or developed.

    问题类似于 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 使用。有办法吗?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2887 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:04 · PVG 22:04 · LAX 07:04 · JFK 10:04
    ♥ Do have faith in what you're doing.