From 4cf9170f308934688e7f767086589cd8cc0a0a85 Mon Sep 17 00:00:00 2001 From: Mattias Ellert Date: Fri, 28 Jun 2019 22:23:49 +0200 Subject: [PATCH] Python 3 compatibility --- tutorials/histfactory/example.py | 2 +- tutorials/pyroot/mrt.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tutorials/histfactory/example.py b/tutorials/histfactory/example.py index 91e1d26939..6ccf3bb350 100755 --- a/tutorials/histfactory/example.py +++ b/tutorials/histfactory/example.py @@ -12,7 +12,7 @@ def main(): try: import ROOT except: - print "It seems that pyROOT isn't properly configured" + print("It seems that pyROOT isn't properly configured") return """ diff --git a/tutorials/pyroot/mrt.py b/tutorials/pyroot/mrt.py index b3a8c0d719..17a73f6881 100644 --- a/tutorials/pyroot/mrt.py +++ b/tutorials/pyroot/mrt.py @@ -10,28 +10,28 @@ ## ## \author Wim Lavrijsen -import sys, string, os -from ROOT import TFile, TNtuple +import sys, os +from ROOT import TFile, TNtuple, TROOT -ifn = os.path.expandvars("${ROOTSYS}/tutorials/pyroot/aptuple.txt") +ifn = os.path.join(str(TROOT.GetTutorialDir()), 'pyroot', 'aptuple.txt') ofn = 'aptuple.root' -print 'opening file', ifn, '...' +print('opening file %s ...' % ifn) infile = open( ifn, 'r' ) lines = infile.readlines() title = lines[0] -labels = string.split( lines[1] ) +labels = lines[1].split() -print 'writing file', ofn, '...' +print('writing file %s ...' % ofn) outfile = TFile( ofn, 'RECREATE', 'ROOT file with an NTuple' ) -ntuple = TNtuple( 'ntuple', title, string.join( labels, ':') ) +ntuple = TNtuple( 'ntuple', title, ':'.join( labels ) ) for line in lines[2:]: - words = string.split( line ) + words = line.split() row = map( float, words ) - apply( ntuple.Fill, row ) + ntuple.Fill(*row) outfile.Write() -print 'done' +print('done') -- 2.21.0