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(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))
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
{ 0, 1, 2 }
{ 0, 1, 2 }
{ 0, 1, 2 }
vector<int>{ 0, 1, 2 }
Name: name Title: title NbinsX: 10
<cppyy.gbl.MyClass object at 0x79a3ea0>
True
- Date
- June 2018
- Author
- Stefan Wunsch, Enric Tejedor
Definition in file pyroot003_prettyPrinting.py.