I am looking for the way to speed up my script. The final output is as required, but it's clunky and really slow. I know it's slow because of the double for..in.. loops. So, how could I make it a bit smoother?My script updates existing feature classes. I have two folders where all up-to-date shapefiles (shp) are stored. My script checks what shps are in each folder, and then searches for the same named featureclasses (these are older versions) in 4 geodatabases. So shp has to go to the gdb that already contains featureclass with the same name. I hope it is simple enough. Just to give you some idea, it takes over 1h to run this script, I have about 45 shapefiles (~1gb), these are copied over to 4 geodatabases.Is there any way to avoid these time consuming double for..in.. loops? I need to mention that folders are stored on different server than gdb's, and that is a main reason of having it so slow. When I tested the script using only C drive it took 6-8minutes!import timeimport arcpystartTime = time.clock()print StartFCProducts = rC:\Python\DataConversion\shapefilesGBProducts = rC:\Python\DataConversion\shapefile_gpadminBdry = rC:\Python\DataConversion\temp1.gdbGnR = rC:\DataConversion\temp2.gdbInvenories = rC:\Python\DataConversion\temp3.gdbNFE = rC:\Python\DataConversion\temp4.gdbarcpy.env.overwriteOutput = Truearcpy.env.workspace = FCProductslistFC = [0]listFC = arcpy.ListFeatureClasses()del arcpy.env.workspacefor product in listFC:    f2fOutput = product[:-4] + _new    arcpy.env.workspace = GnR    listGnrFC = arcpy.ListFeatureClasses()    for gnrFC in listGnrFC:        if gnrFC == product[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(product[:-4], GnR, f2fOutput)            print product,  copied to , GnR            arcpy.Delete_management(gnrFC)            print old , gnrFC,  deleted            arcpy.Rename_management(f2fOutput, product[:-4])            print output renamed, \n    arcpy.env.workspace = adminBdry    listAdBdryFC = arcpy.ListFeatureClasses()    for AdBdry in listAdBdryFC:        if AdBdry == product[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(product[:-4], adminBdry, f2fOutput)            print product,  copied to , adminBdry            arcpy.Delete_management(AdBdry)            print old , AdBdry,  deleted            arcpy.Rename_management(f2fOutput, product[:-4])            print output renamed, \n    arcpy.env.workspace = Invenories    listInventFC = arcpy.ListFeatureClasses()    for invent in listInventFC:        if invent == product[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(product[:-4], Invenories, f2fOutput)            print product,  copied to , Invenories            arcpy.Delete_management(invent)            print old , invent,  deleted            arcpy.Rename_management(f2fOutput, product[:-4])            print output renamed, \n    arcpy.env.workspace = NFE    listNfeFC = arcpy.ListFeatureClasses()    for nfe in listNfeFC:        if nfe == product[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(product[:-4], NFE, f2fOutput)            print product,  copied to , NFE            arcpy.Delete_management(nfe)            print old , nfe,  deleted            arcpy.Rename_management(f2fOutput, product[:-4])            print output renamed, \narcpy.env.workspace = GBProductslistFCgb = [0]listFCgb = arcpy.ListFeatureClasses()for productGB in listFCgb:    f2fOutputGB = productGB[:-4] + _new    arcpy.env.workspace = Invenories    listInventGB = arcpy.ListFeatureClasses()    for InventGB in listInventGB:        if InventGB == productGB[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(productGB[:-4], Invenories, f2fOutputGB)            print productGB,  copied to , Invenories            arcpy.Delete_management(InventGB)            print old , InventGB,  deleted            arcpy.Rename_management(f2fOutputGB, productGB[:-4])            print output renamed, \n    arcpy.env.workspace = NFE    listNfeGB = arcpy.ListFeatureClasses()    for nfeGB in listNfeGB:        if nfeGB == productGB[:-4]:            arcpy.FeatureClassToFeatureClass_conversion(productGB[:-4], NFE, f2fOutputGB)            print productGB,  copied to , NFE            arcpy.Delete_management(nfeGB)            print old , nfeGB,  deleted            arcpy.Rename_management(f2fOutputGB, productGB[:-4])            print output renamed, \nprint completed within:, time.clock() - startTime, seconds, \nI am using Windows XP, ArcGis 10.0, Python 2.6.6 
Updating ArcPy feature classes
python;performance;python 2.6
Don't repeat yourselfFirst, and of the least significance, Python spend more time building a substring rather than a local variable lookup. Thus you could improve thing a bit by naming product[:-4] at the start of your loop.More importantly, the majority of your code is similar:set a new workspace;build a list of classes out of it;for each of these classes:convert the class;delete the old one;rename the new one.The only things that change are: the name of the workspace and the name of the product involved. Just write a function to handle it once:import arcpyFCProducts = rC:\Python\DataConversion\shapefilesGBProducts = rC:\Python\DataConversion\shapefile_gpadminBdry = rC:\Python\DataConversion\temp1.gdbGnR = rC:\DataConversion\temp2.gdbInvenories = rC:\Python\DataConversion\temp3.gdbNFE = rC:\Python\DataConversion\temp4.gdbarcpy.env.overwriteOutput = Truedef convert_class(workspace, product_name, output_name):    arcpy.env.workspace = workspace    for product in arcpy.ListFeatureClasses():        if product == product_name:            arcpy.FeatureClassToFeatureClass_conversion(product_name, workspace, output_name)            print product_name,  copied to , workspace            arcpy.Delete_management(product)            print old , product,  deleted            arcpy.Rename_management(output_name, product_name)            print output renamed, \narcpy.env.workspace = FCProductslistFC = arcpy.ListFeatureClasses()for product in listFC:    f2fOutput = product[:-4] + _new    product_name = product[:-4]    convert_class(GnR, product_name, f2fOutput)    convert_class(adminBdry, product_name, f2fOutput)    convert_class(Invenories, product_name, f2fOutput)    convert_class(NFE, product_name, f2fOutput)arcpy.env.workspace = GBProductslistFCgb = arcpy.ListFeatureClasses()for productGB in listFCgb:    f2fOutputGB = productGB[:-4] + _new    product_name = productGB[:-4]    convert_class(Invenories, product_name, f2fOutput)    convert_class(NFE, product_name, f2fOutput)Use resources sparinglyNow that the code is simpler to read, what exactly is it doing? For each item you are switching workspaces 2 or 4 times. Switching workspace meaning:opening a file;reading it;parsing it;building data structures out of it.Doing that even once for each item is an enormous waste of time and computing resources. Better opening a workspace once, iterating over each product and then switching to an other workspace. The code layout for a single workspace would be something like:def process_workspace(workspace, products):    arcpy.env.workspace = workspace    for product in products:        product_name = product[:-4]        output_name = product_name + _new        for item in arcpy.ListFeatureClasses():            if item == product_name:                arcpy.FeatureClassToFeatureClass_conversion(product_name, workspace, output_name)                print product,  copied to , workspace                arcpy.Delete_management(item)                print old , item,  deleted                arcpy.Rename_management(output_name, product_name)                print output renamed\nYou then just need to change workspace once before each of your *.gdb processing:arcpy.env.workspace = FCProductslistFC = arcpy.ListFeatureClasses()process_workspace(GnR, listFC)process_workspace(adminBdry, listFC)process_workspace(Invenories, listFC)process_workspace(NFE, listFC)arcpy.env.workspace = GBProductslistGB = arcpy.ListFeatureClasses()process_workspace(Invenories, listGB)process_workspace(NFE, listGB)You could even improve the layout with for loop over the workspaces.Putting it all togetherBy sticking a little bit more to PEP8 on line length and variable naming, we can end up with:import arcpyFC_PRODUCTS = rC:\Python\DataConversion\shapefilesGB_PRODUCTS = rC:\Python\DataConversion\shapefile_gpADMIN_BOUNDARY = rC:\Python\DataConversion\temp1.gdbGNR = rC:\DataConversion\temp2.gdbINVENORIES = rC:\Python\DataConversion\temp3.gdbNFE = rC:\Python\DataConversion\temp4.gdbdef process_workspace(workspace, products):    arcpy.env.workspace = workspace    for product in products:        product_name = product[:-4]        output_name = product_name + _new        for item in arcpy.ListFeatureClasses():            if item == product_name:                arcpy.FeatureClassToFeatureClass_conversion(                    product_name, workspace, output_name)                print product,  copied to , workspace                arcpy.Delete_management(item)                print old , item,  deleted                arcpy.Rename_management(output_name, product_name)                print output renamed\narcpy.env.workspace = FC_PRODUCTSproducts = arcpy.ListFeatureClasses()for workspace in (GNR, ADMIN_BOUNDARY, INVENORIES, NFE):    process_workspace(workspace, products)arcpy.env.workspace = GB_PRODUCTSproducts = arcpy.ListFeatureClasses()for workspace in (INVENORIES, NFE):    process_workspace(workspace, products)