Skip to content
Snippets Groups Projects
Commit 9190f6f9 authored by Mattias Ellert's avatar Mattias Ellert Committed by Guilherme Amadio
Browse files

Python 3 compatibility

parent d285d0dd
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ def main(): ...@@ -12,7 +12,7 @@ def main():
try: try:
import ROOT import ROOT
except: except:
print "It seems that pyROOT isn't properly configured" print("It seems that pyROOT isn't properly configured")
return return
""" """
......
...@@ -10,28 +10,28 @@ ...@@ -10,28 +10,28 @@
## ##
## \author Wim Lavrijsen ## \author Wim Lavrijsen
import sys, string, os import sys, os
from ROOT import TFile, TNtuple 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' ofn = 'aptuple.root'
print 'opening file', ifn, '...' print('opening file %s ...' % ifn)
infile = open( ifn, 'r' ) infile = open( ifn, 'r' )
lines = infile.readlines() lines = infile.readlines()
title = lines[0] 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' ) 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:]: for line in lines[2:]:
words = string.split( line ) words = line.split()
row = map( float, words ) row = map( float, words )
apply( ntuple.Fill, row ) ntuple.Fill(*row)
outfile.Write() outfile.Write()
print 'done' print('done')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment