Python script not disconnecting from Geodatabase after editing

751
2
07-23-2012 07:33 AM
MatthewGerbrandt
New Contributor II
I've written a python script that reads an XML file and inserts the XML data into a file geodatabase. The script works great with the exception that it appears that the code does not detach from the FeatureClass. The symptom is as follows:

I create a duplicate of the feature class to test the code. I run the python code against the new test feature class and it run successfully. I go into ArcCatalog and attempt to delete the new test feature class by right-clicking on the object and choosing "Delete". I get the following error: "Failed to delete the selected object(s)".

I need help figuring out how to get my python script to let go of this feature class when it's done. All help is greatly appreciated.

Here's my code:

import arcpy, xml.etree.ElementTree as ET 

arcpy.DeleteRows_management("C:/Data/GISData/DBName.gdb/SitesTest6")

# Code for accessing the XML file
tree = ET.parse("XMLTest.xml")
root = tree.getroot()
iter = root.getiterator() 

# Create insert cursor for table
rows = arcpy.InsertCursor("C:/Data/GISData/DBName.gdb/SitesTest6")

# Create new rows. Set the initial row ID and distance values
for element in iter:
    row = rows.newRow()
    if element.tag == "SiteID":
        vSiteID = element.text
    if element.tag == "SiteName":
        vSiteName = element.text
    if element.tag == "Address1":
        vAddress1 = element.text
    if element.tag == "City":
        vCity = element.text
    if element.tag == "State":
        vState = element.text
    if element.tag == "ZIP":
        vZIP = element.text
    if element.tag == "ContactName":
        vContactName = element.text
    if element.tag == "ContactEmail":
        vContactEmail = element.text
    if element.tag == "ContactTitle":
        vContactTitle = element.text
    if element.tag == "SiteCategory":
        vSiteCategory = element.text
    if element.tag == "Latitude":
        vLatitude = element.text
    if element.tag == "Longitude":
        vLongitude = element.text
    if element.tag == "URL":
        vURL = element.text
    if element.tag == "Images":
        vImages = element.text
    if element.tag == "Documents":
        vDocuments = element.text
    if element.tag == "PolSitReps":
        vPolSitReps = element.text
    if element.tag == "Contacts":
        vContacts = element.text
    
    if element.tag == "Links":   # Last element in each dataset. Also, not needed
       row.SiteID = vSiteID
       row.SiteName = vSiteName
       row.SiteAddress1 = vAddress1
       row.SiteCity = vCity
       row.SiteState = vState
       row.SiteZIP = vZIP
       row.ContactName = vContactName
       row.ContactEmail = vContactEmail
       row.ContactTitle = vContactTitle
       row.SiteCategory = vSiteCategory
       row.Latitude = vLatitude
       row.Longitude = vLongitude
       row.SiteAbstractURI = vSiteAbstractURI
       rows.insertRow(row)


# Delete cursor and row objects to remove locks on the data 
del row 
del rows
del iter
del root
del tree

Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
Have you tried using a function? Do you get this issue even after you end the process of whatever program is executing your script?
0 Kudos
MatthewGerbrandt
New Contributor II
Looks like the problem was that I had the script open in the IDLE editor. As soon as I closed the Python editor, I could delete the feature class. Go figure. Thanks for your reply, Matt!
0 Kudos