python - 将 C++ 类指针的向量发送到 python

标签 python class wrapper root-framework

我在将 std 向量传递给 python 时遇到问题。

   std::vector<TMVA::Interval*> parameterRanges;
   parameterRanges.push_back(new TMVA::Interval(-10,10)); 
   parameterRanges.push_back(new TMVA::Interval(0.1,10)); 
   parameterRanges.push_back(new TMVA::Interval(0,2000));

我必须在 python 中做到这一点。不幸的是我无法更改 Interval C++ 类。 我可以在 python 中使用 std.vector,但只能使用 std.vector('double') 或 int,但不能使用对象类型。

你有什么想法吗?

最佳答案

由于您正在使用 TMVA,我假设您也拥有 ROOT。还有一个用于 pyroot 的 ROOT std::vector 包装器。其使用方法如下:

import ROOT
VectorOfIntervalPointer = ROOT.std.vector('TMVA::Interval*')
# this is only a constructor, not an instance!

instance = VectorOfIntervalPointer()
from ROOT import TMVA.Interval
instance.push_back(TMVA.Interval(-10,10))

关于python - 将 C++ 类指针的向量发送到 python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28665049/

相关文章:

python - PyCharm PEP8 代码样式突出显示不起作用

python - 如何在 python 中找到唯一类别的优先级值?

c# - 不是按名称而是按类型指定接口(interface)成员

c++ - 具有冲突名称的类的构造函数

python - 将类的属性和确定它的方法分开是否可以/pythonic?

python - 根据实例化的是异步实例还是同步实例返回包装器

html - 包装器 div 的背景图像不起作用

python - Spotipy——无需身份验证即可访问公共(public)播放列表中的轨道

python - 如何在 sqlalchemy 中强制执行 sqlite select 更新事务行为

java - isDigit() 为字母返回 true