Python 与'有关的问题;试试……除了';引发根文件的语法错误
我试图在目录中找到损坏的根文件。基本上,我的代码在尝试以下操作时抛出和SyntaxError:invalid语法Python 与'有关的问题;试试……除了';引发根文件的语法错误,python,Python,我试图在目录中找到损坏的根文件。基本上,我的代码在尝试以下操作时抛出和SyntaxError:invalid语法 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") e
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()
我也尝试了Exception:但这也不起作用。您的
Exception
语句必须与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()
您的
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()
哦,对了,谢谢!但是,代码仍然存在于第一个损坏的文件中
回溯(上次调用):文件“check.py”,第17行,打印“文件名是”,文件myTree.GetEntries()AttributeError:“ToObject”对象没有属性“GetEntries”@Terma这表示您的
f.Get
没有触发错误,但返回的对象与您预期的不同。此线程表示您应该使用f.GetObject
而不是f.Get
:哦,对了,谢谢!但是,代码仍然存在于第一个损坏的文件中回溯(上次调用):文件“check.py”,第17行,打印“文件名是”,文件myTree.GetEntries()AttributeError:“ToObject”对象没有属性“GetEntries”@Terma这表示您的
f.Get
没有触发错误,但返回的对象与您预期的不同。此线程表示应该使用f.GetObject
而不是f.Get
: