Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 与'有关的问题;试试……除了';引发根文件的语法错误_Python - Fatal编程技术网

Python 与'有关的问题;试试……除了';引发根文件的语法错误

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

我试图在目录中找到损坏的根文件。基本上,我的代码在尝试以下操作时抛出和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")

        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