在C++中运行 python 对象
Run python object in C++
我只是有一个关于在C++中运行python对象的问题。 让我在下面的示例中解释我想做什么。
int main () {
// as you know, the python object has its member variables etc, and
// I want it to be initialized only once
py = python_object();
while (1) {
// here, I am hoping to call a member function from the object continously
// and get a return value.
int abc = py.get_num();
if (abc < 0) break;
do_something_in_my_cpp_code();
}
}
我在这里谈论的python对象捕获oOjbect。
我想知道,如果你们有任何处理这样的事情的经验,这会有多困难。 我也对其他可能的方法持开放态度,例如相反(在python脚本中运行C++对象(。谢谢!
解决方案 1创建一个小型 Python 脚本,用于调用函数并打印结果。 然后,在C++程序中使用popen调用python脚本并检索显示的值。
解决方案 2在 C++ 程序中嵌入 Python https://docs.python.org/2/extending/embedding.html
如果你只有很少的 Python 调用,我认为解决方案 1 是更快、更安全的方法。
相关文章:
- Pybind11:使用 for 循环使用 OpenMP 访问 python 对象
- 从从该抽象类派生的 Python 对象强制转换C++抽象类C++
- 如何创建和使用存储为 c++ 对象的 python 对象?
- 在C++中运行 python 对象
- 如何将 Python 对象转换为 Cython 扩展类型的 std::vector 并返回?
- 在 boost::p ython 中的 python 对象中运行 python 代码
- 添加 swig pythoncode 以在 Python 对象上设置自己的标志
- C DLL中的Python对象
- Boost.Python 返回引用现有 c++ 对象的 python 对象
- 如何使用CTYPE将此Python对象移至C
- 如何使用 boost::p ython 创建和使用 Python 对象的实例
- 如何在Cython中将Python对象转换为C++类型
- Python 对象不可迭代或下标
- 从C 内部在本地范围中创建Python对象
- 将大型python对象存储在RAM中以备将来使用
- 在C++中使用Python对象
- Python 对象删除检测
- 将 python 对象传递到用 Cython 包装的类时出现 Seg 错误
- 提高python对象的生存期
- Boost::Python Boost:的正向声明:Python::对象抛出Python TypeError