I was writing a code to compare the fields within some feature classes that are in 2 seperate geodatabases. The geodatabses contain the same feature classes, but the feature classes have different fields.
- Loop through first geodatabase
- Loop through second geaodatabase and find the matching feature class
- Loop through the matching feature classes and print the list of fields for each into a spreadsheet
env.workspacebut that only sets a workspace for the first geodatabase. I tried setting variables to 2 different workspaces (workspace1 and workspace2) but that doesn't seem to work. Can someone suggest how to set seperate workspaces so I can loop through 2 different geodatabases in the same script?
import arcpy, xlwt, traceback, sys from arcpy import env from xlwt import * workspace1 = env.workspace = r"Z:\test1.gdb" workspace2 = env.workspace = r"Z:\test2.gdb" try: # Create the excel workbook book = Workbook() z = 2 x = 2 y = 1 for fc in arcpy.ListFeatureClasses(workspace1): print fc for fc2 in arcpy.ListFeatureClasses(workspace2): print fc2 if fc == fc2: print fc + " = " + fc2 sheet1 = book.add_sheet(fc) sheet1.write(0,0, fc) sheet1.write(1,0, "IOR Field Name") sheet1.write(1,1, "IOR Field Type") sheet1.write(1,2, "Field Length") sheet1.write(1,5, "JC Field Name") sheet1.write(1,6, "JC Field Type") sheet1.write(1,7, "JC Field Length") sheet1.col(0).width = 8000 sheet1.col(1).width = 3000 sheet1.col(2).width = 3000 sheet1.col(5).width = 8000 sheet1.col(6).width = 3000 sheet1.col(7).width = 3000 y += 1 for field in arcpy.ListFields(fc): x+=1 sheet1.write(x,0, field.name) sheet1.write(x,1, field.type) sheet1.write(x,2, field.length) for field2 in arcpy.ListFields(fc2): z+=1 sheet1.write(z,5, field.name) sheet1.write(z,6, field.type) sheet1.write(z,7, field.length) book.save(r"Z:" + "\\" + "Template_Geodatabase_FieldList2" + ".xls")