Std::ostream in python

Dear ROOT and python experts,

I’m trying to call SavePrimitive() on a THStack in python, which requires a parameter for the output stream. Could you point me to how I could achieve this. I tried sys.stdout, which didn’t work.

Thanks, Johann

I guess @etejedor can most probably give you some hints

Hi Johann,

You can try with ROOT.std.cout or any other ostream that you create from Python.

Cheers,
Enric

Hi Enric,

thanks for the fast reply! Could you maybe give me an example on how to use this? For me this basic example results in an error:

import ROOT
stack = ROOT.THStack("test","test")
stack.SavePrimitive(ROOT.std.cout)

The error message is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/cvmfs/sft.cern.ch/lcg/app/releases/ROOT/6.16.00/x86_64-centos7-gcc48-opt/lib/cppyy.py", line 177, in __getattr__
    raise AttributeError(str(e))
AttributeError: requested class 'cout' does not exist

Thanks,

Johann

A colleague just pointed me to the solution, which is using ROOT.cout. He found it on: Using ROOT::Fit::FitResult::Print method with pyroot: Ofstream

Cheers, Johann

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