1

I have a folder with several .SDE connections. I want my Python code to execute various SDE maintenance procedures (such as compress) on each of these databases. If there is a bad/corrupt/not permissioned .SDE file in the workspace, the process doesn't execute on any of the other databases either. How do I get it to attempt to compress each database in the workspace, even if one fails?

import arcpy

arcpy.env.workspace = "F:/Scripts/DatabaseConnections"

workspaces = arcpy.ListWorkspaces("*", "SDE")

try:
    for workspace in workspaces:
        arcpy.Compress_management(workspace)
except:  
    arcpy.GetMessages()

1 Answer 1

6

Here, just reorganize your try/except block and put it inside the for loop:

for workspace in workspaces:
    try:
        arcpy.Compress_management(workspace)
    except:  
        arcpy.GetMessages()
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.