我正在尝试在目录中找到损坏的根文件。基本上,尝试以下操作时,我的代码将抛出SyntaxError:无效语法
import ROOT as root
import sys
import glob
dir=sys.argv[1]
txtfiles = []
for file in glob.glob(dir+"/*.root"):
f = root.TFile(file,'r')
try :
myTree = f.Get("AC1B")
except IOError:
print 'this is not good',f
continue
else :
print 'the filename is ',file, myTree.GetEntries()
我也尝试过,除了:但这也不起作用。
答案 0 :(得分:5)
您的except
语句必须与try
处于相同的缩进级别。它当前嵌套在try
中:
import ROOT as root
import sys
import glob
dir = sys.argv[1]
txtfiles = []
for file in glob.glob(dir + "/*.root"):
f = root.TFile(file,'r')
try:
myTree = f.Get("AC1B")
except IOError:
print 'this is not good',f
continue
else:
print 'the filename is ',file, myTree.GetEntries()