How to set 2 workspace environments?

Discussion created by BrokenLegMike on May 14, 2012
Latest reply on May 15, 2012 by josborneesri-ca-esridist
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.

  1. Loop through first geodatabase

  2. Loop through second geaodatabase and find the matching feature class

  3. Loop through the matching feature classes and print the list of fields for each into a spreadsheet

My following code wasn't working, and I narrowed it down to the loop through the second feature class. I went back and the syntax requires that a workspace be set to list feature classes. I did that using
but 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"
    # 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):
                        sheet1.write(x,1, field.type)
                        sheet1.write(x,2, field.length)
                    for field2 in arcpy.ListFields(fc2):
                        sheet1.write(z,6, field.type)
                        sheet1.write(z,7, field.length)

      "Z:" + "\\" + "Template_Geodatabase_FieldList2" + ".xls")