This tutorial illustrates the pretty printing feature of PyROOT, which reveals the content of the object if a string representation is requested, e.g., by Python's print statement.
The printing behaves similar to the ROOT prompt powered by the C++ interpreter cling.
import ROOT
obj = ROOT.std.vector("int")(3)
for i in range(obj.size()):
obj[i] = i
print(obj)
print(str(obj))
print("{}".format(obj))
print(repr(obj))
obj
hist = ROOT.TH1F("name", "title", 10, 0, 1)
print(hist)
ROOT.gInterpreter.Declare('class MyClass {};')
m = ROOT.MyClass()
print(m)
print(str(m) == repr(m))
{ 0, 1, 2 }
{ 0, 1, 2 }
{ 0, 1, 2 }
<cppyy.gbl.std.vector<int> object at 0x6217ea0>
Name: name Title: title NbinsX: 10
<cppyy.gbl.MyClass object at 0x6f15600>
True
- Date
- June 2018
- Author
- Stefan Wunsch, Enric Tejedor
Definition in file pyroot003_prettyPrinting.py.