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 }
<ROOT.vector<int> object at 0x55c550c4e700>
Name: name Title: title NbinsX: 10
<ROOT.MyClass object at 0x55c550f11770>
True
- Date
- June 2018
- Author
- Stefan Wunsch, Enric Tejedor
Definition in file pyroot003_prettyPrinting.py.