Passing python list to a root macro as a vector without compiling

I need some help on how to pass a python list to a ROOT macro as a std::vector. There are way of using boost::python but it seems the c++ code need to be compiled. I’m hoping to pass it in the following way, for example:

//// ROOT macro
void test(vector &in)
cout<< in.size()<<endl;

//… python script
import os
list = [“a”, “b”, “c”, “d”]
os.system("root -b -q ‘test(list)’ ")

The python script as is will not work. Any hint on how to do it in this style is appreciated.


There is no automatic conversion from Python list to std::vector. So from Python, you can do:

import ROOT
from ROOT import gROOT
v = ROOT.std.vector('char')()
for c in ['a', 'b', 'c', 'd']:

That works great. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.