IOError: [Errno 13] Permission denied:

ⅰ亾dé卋堺 提交于 2019-12-20 03:36:09

问题


I have built this code to specifically identify a load of .XML files and to extract co-ordinates from those files. 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! Does anyone have any idea what has gone wrong?


回答1:


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.




回答2:


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"


来源:https://stackoverflow.com/questions/4736616/ioerror-errno-13-permission-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!