【问题标题】:Export variable into python from C++ using boost.python使用 boost.python 将变量从 C++ 导出到 python
【发布时间】:2011-03-15 19:50:05
【问题描述】:

例如,我有一个 c++ 变量:

const float Pi = 3.1415926535898f;

使用 boost.python 将其导出到 python-module 的最佳方法是什么?

我想在全局范围内将其作为变量访问。

【问题讨论】:

    标签: c++ python variables boost export


    【解决方案1】:

    似乎可以使用以下方法轻松完成:

    boost::python::scope().attr("Pi") = Pi; 
    

    【讨论】:

    • 有没有办法在 Pybind11 中这样做?
    【解决方案2】:

    如果你想将 PyModule_AddObject 注入到从 python 文件导入的模块中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 2011-01-01
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 2020-04-30
      相关资源
      最近更新 更多