Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.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 os.path.walk可以';无法打开文件 #python prepbrd.py 检查。 检查/恶心 检查。 发现erct.brd 检查/恶心 找到nautctrl.brd 回溯(最近一次呼叫最后一次): 文件“prepbrd.py”,第43行,在 os.path.walk(基本目录、sanBrds、无) 文件“/usr/lib/python2.6/posixpath.py”,第236行,在walk中 walk(名称、函数、参数) 文件“/usr/lib/python2.6/posixpath.py”,第228行,在walk中 func(参数、顶部、名称) sanBrds中第22行的文件“prepbrd.py” tree=etree.parse(文件) lxml.etree.parse(src/lxml/lxml.etree.c:49958)中的文件“lxml.etree.pyx”,第2706行 文件“parser.pxi”,第1500行,在lxml.etree.\u parseDocument(src/lxml/lxml.etree.c:71797)中 文件“parser.pxi”,第1529行,在lxml.etree.\u parseDocumentFromURL(src/lxml/lxml.etree.c:72080)中 文件“parser.pxi”,第1429行,在lxml.etree.\u parseDocFromFile(src/lxml/lxml.etree.c:71175)中 文件“parser.pxi”,第975行,在lxml.etree.\u BaseParser.\u parseDocFromFile(src/lxml/lxml.etree.c:68173)中 文件“parser.pxi”,第539行,在lxml.etree.\u ParserContext.\u handleParseResultDoc_Python - Fatal编程技术网

python os.path.walk可以';无法打开文件 #python prepbrd.py 检查。 检查/恶心 检查。 发现erct.brd 检查/恶心 找到nautctrl.brd 回溯(最近一次呼叫最后一次): 文件“prepbrd.py”,第43行,在 os.path.walk(基本目录、sanBrds、无) 文件“/usr/lib/python2.6/posixpath.py”,第236行,在walk中 walk(名称、函数、参数) 文件“/usr/lib/python2.6/posixpath.py”,第228行,在walk中 func(参数、顶部、名称) sanBrds中第22行的文件“prepbrd.py” tree=etree.parse(文件) lxml.etree.parse(src/lxml/lxml.etree.c:49958)中的文件“lxml.etree.pyx”,第2706行 文件“parser.pxi”,第1500行,在lxml.etree.\u parseDocument(src/lxml/lxml.etree.c:71797)中 文件“parser.pxi”,第1529行,在lxml.etree.\u parseDocumentFromURL(src/lxml/lxml.etree.c:72080)中 文件“parser.pxi”,第1429行,在lxml.etree.\u parseDocFromFile(src/lxml/lxml.etree.c:71175)中 文件“parser.pxi”,第975行,在lxml.etree.\u BaseParser.\u parseDocFromFile(src/lxml/lxml.etree.c:68173)中 文件“parser.pxi”,第539行,在lxml.etree.\u ParserContext.\u handleParseResultDoc

python os.path.walk可以';无法打开文件 #python prepbrd.py 检查。 检查/恶心 检查。 发现erct.brd 检查/恶心 找到nautctrl.brd 回溯(最近一次呼叫最后一次): 文件“prepbrd.py”,第43行,在 os.path.walk(基本目录、sanBrds、无) 文件“/usr/lib/python2.6/posixpath.py”,第236行,在walk中 walk(名称、函数、参数) 文件“/usr/lib/python2.6/posixpath.py”,第228行,在walk中 func(参数、顶部、名称) sanBrds中第22行的文件“prepbrd.py” tree=etree.parse(文件) lxml.etree.parse(src/lxml/lxml.etree.c:49958)中的文件“lxml.etree.pyx”,第2706行 文件“parser.pxi”,第1500行,在lxml.etree.\u parseDocument(src/lxml/lxml.etree.c:71797)中 文件“parser.pxi”,第1529行,在lxml.etree.\u parseDocumentFromURL(src/lxml/lxml.etree.c:72080)中 文件“parser.pxi”,第1429行,在lxml.etree.\u parseDocFromFile(src/lxml/lxml.etree.c:71175)中 文件“parser.pxi”,第975行,在lxml.etree.\u BaseParser.\u parseDocFromFile(src/lxml/lxml.etree.c:68173)中 文件“parser.pxi”,第539行,在lxml.etree.\u ParserContext.\u handleParseResultDoc,python,Python,(src/lxml/lxml.etree.c:64257) lxml.etree.中的文件“parser.pxi”,第625行。\u handleParseResult(src/lxml/lxml.etree.c:65178) 文件“parser.pxi”,第563行,在lxml.etree中。\u raiseParserError(src/lxml/lxml.etree.c:64493) IOError:读取文件“nautctrl.brd”时出错:无法加载外部实体“nautctrl.brd”

(src/lxml/lxml.etree.c:64257) lxml.etree.中的文件“parser.pxi”,第625行。\u handleParseResult(src/lxml/lxml.etree.c:65178) 文件“parser.pxi”,第563行,在lxml.etree中。\u raiseParserError(src/lxml/lxml.etree.c:64493) IOError:读取文件“nautctrl.brd”时出错:无法加载外部实体“nautctrl.brd”


我对这方面还不太熟悉,但似乎我没有正确地将参数从os.path.walk传递到其他函数。我想先删除以_pyclean.brd结尾的所有文件,然后对其余的.brd文件(xml)进行操作。这些函数在平面目录中工作正常,但递归地出现上述错误。

文件中的文件名是短名称。您想使用可以使用
os.path.join
生成的完整路径:

# python prepbrd.py
checking .
checking ./naut
checking .
found erct.brd
checking ./naut
found nautctrl.brd
Traceback (most recent call last):
  File "prepbrd.py", line 43, in <module>
    os.path.walk(base_dir,sanBrds,None)
  File "/usr/lib/python2.6/posixpath.py", line 236, in walk
    walk(name, func, arg)
  File "/usr/lib/python2.6/posixpath.py", line 228, in walk
    func(arg, top, names)
  File "prepbrd.py", line 22, in sanBrds
    tree=etree.parse(file)
  File "lxml.etree.pyx", line 2706, in lxml.etree.parse (src/lxml/lxml.etree.c:49958)
  File "parser.pxi", line 1500, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:71797)
  File "parser.pxi", line 1529, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:72080)
  File "parser.pxi", line 1429, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:71175)
  File "parser.pxi", line 975, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:68173)
  File "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc

文件中的文件名是短名称。您想使用可以使用
os.path.join
生成的完整路径:

# python prepbrd.py
checking .
checking ./naut
checking .
found erct.brd
checking ./naut
found nautctrl.brd
Traceback (most recent call last):
  File "prepbrd.py", line 43, in <module>
    os.path.walk(base_dir,sanBrds,None)
  File "/usr/lib/python2.6/posixpath.py", line 236, in walk
    walk(name, func, arg)
  File "/usr/lib/python2.6/posixpath.py", line 228, in walk
    func(arg, top, names)
  File "prepbrd.py", line 22, in sanBrds
    tree=etree.parse(file)
  File "lxml.etree.pyx", line 2706, in lxml.etree.parse (src/lxml/lxml.etree.c:49958)
  File "parser.pxi", line 1500, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:71797)
  File "parser.pxi", line 1529, in lxml.etree._parseDocumentFromURL (src/lxml/lxml.etree.c:72080)
  File "parser.pxi", line 1429, in lxml.etree._parseDocFromFile (src/lxml/lxml.etree.c:71175)
  File "parser.pxi", line 975, in lxml.etree._BaseParser._parseDocFromFile (src/lxml/lxml.etree.c:68173)
  File "parser.pxi", line 539, in lxml.etree._ParserContext._handleParseResultDoc
def sanBrds(args, dirname, files):
    print "checking ", dirname
    for file in files:
        fullpath = os.path.join(dirname, file)
        if fullpath.endswith(".brd"):
            print "found ", file
            newfile = splitext(basename(fullpath))[0] + "_pyclean.brd"
            tree = etree.parse(fullpath)
            # ...