Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 872
Alice Duff Avatar asked Nov 27 '25 20:11

Alice Duff


1 Answers

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.

like image 196
Spaceghost Avatar answered Nov 30 '25 09:11

Spaceghost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!