简体   繁体   English

IOError:[Errno 13]权限被拒绝:

[英]IOError: [Errno 13] Permission denied:

I have built this code to specifically identify a load of .XML files and to extract co-ordinates from those files. 我已经构建了这个代码来专门识别一堆.XML文件并从这些文件中提取坐标。 Here is my code: 这是我的代码:

from xml.etree import ElementTree as ET
import sys, string, os, arcgisscripting
gp = arcgisscripting.create(9.3)

workspace = "D:/J040083"
gp.workspace = workspace

for root, dirs, filenames in os.walk(workspace): # returms root, dirs, and files
    for filename in filenames:
        filename_split = os.path.splitext(filename) # filename and extensionname (extension in [1])
        filename_zero = filename_split[0]
        extension = str.upper(filename_split[1])

        try:
            first_2_letters = str.upper(filename_zero[0] + filename_zero[1])
        except:
            first_2_letters = "XX"

        if first_2_letters == "LI" and extension == ".XML":
            tree = ET.parse(workspace)
            print tree.find('//{http://www.opengis.net/gml}lowerCorner').text
            print tree.find('//{http://www.opengis.net/gml}upperCorner').text

I am having trouble with an error: 我遇到了错误:

Message File Name   Line    Position    
Traceback               
    <module>    D:\J040083\TXT_EXTRACTION.py    32      
    parse   C:\Python25\Lib\xml\etree\ElementTree.py    862     
    parse   C:\Python25\Lib\xml\etree\ElementTree.py    579     
IOError: [Errno 13] Permission denied: 'D:/J040083'     

I definitely do have access to this folder! 我绝对可以访问这个文件夹! I have also tried making new, empty folders and putting just one .xml file in there but i get the same error! 我也尝试制作新的空文件夹并在其中放入一个.xml文件,但我得到同样的错误! Does anyone have any idea what has gone wrong? 有谁知道出了什么问题?

You need to change the line 你需要改变这条线

tree = ET.parse(workspace)

to

tree = ET.parse(filename)

because workspace is a directory and the parse method takes a filename. 因为workspace是一个目录,而parse方法采用文件名。

Maybe you just need to write the file path with \\ instead of / : 也许你只需要用\\而不是/来编写文件路径:

workspace = "D:\\J040083"

Or, without backslash escaping as a raw string: 或者,没有反斜杠作为原始字符串转义:

workspace = r"D:\J040083"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM