# For each Layer Package the user has provided for LPK in LPK_list: # Extract the Layer Package Metadata and store it in the variable 'desc' desc = arcpy.Describe(LPK) # Extract the name of the Layer Package from the Metadata and store it in the variable 'name' name = desc.name """If the 'name' is 'COF_Branches':""" if name == "COF_Branches.lpk": """Establish the Target Name""" TargetName = "COF_Branches" """Establish the Feature Dataset name""" FD = "Branches" # Unpack the Layer Package to the srcExtractDir arcpy.ExtractPackage(LPK, srcExtractDir) # Acquire the Source Layer File from the srcExtractFolder srcLYRFile = srcExtractFolder + "\\0000" + str(TargetName) + ".lyr" # Validate that the Layer File was acquired, raising a Fatal Error if the Layer File acquisition was unsuccessful if arcpy.Exists(srcLYRFile) == False: arcpy.AddError("An error occured while unpacking '" + str(name) + "'. The result Layer File could not be acquired. \ Unable to continue. Contact GIS Manager.") # Rename the Source Layer File to match the existing naming convention arcpy.Rename_management(srcLYRFile, str(TargetName) + ".lyr") # Reacquire the Source Layer File with the updated name, this time instantiating it as a Layer object srcLYRFile = arcpy.mapping.Layer(srcExtractFolder + "\\" + str(TargetName) + ".lyr") # Validate that the Layer File was reacquired, raising a Fatal Error if the Layer File acquisition was unsuccessful if arcpy.Exists(srcLYRFile) == False: arcpy.AddError("An error occured while reacquiring the updated source Layer File. '" + str(srcLYRFile) + "' could not \ be reacquired. Unable to continue. Contact GIS Manager.") # Acquire the MXDs Target Feature Layer to update try: FeatureLayer = arcpy.mapping.Layer('"' + str(TargetName) + '"') except: arcpy.AddError("An error occured while trying to acquire the Map Layer. '" + str(FeatureLayer) + "' could not be \ acquired. Unable to continue. Contact GIS Manager.") # Update the MXD's Feature Layer to reference the source Layer File ## This step is performed so that the 'tgtFC' which is to be updated with the 'srcFC', can be deleted from disk, ## while bypassing the automatic RemoveLayer() event that would occur in ArcMap if the 'srcFC' referenced by the ## MXD's 'FeatureLayer' were to be deleted while the 'FeatureLayer' is still referencing the 'srcFC'. arcpy.mapping.UpdateLayer(df, FeatureLayer, srcLYRFile, False) """ Update the Source Data """ # Acquire the Source Feature Class srcFC = srcExtractGDB + "\\" + str(FD) + "\\" + str(TargetName) # Validate that the Source Feature Class was acquired, raising a Fatal Error if the Feature Class acquisition was unsuccessful if arcpy.Exists(srcFC) == False: arcpy.AddError("An error occured while acquiring the source Feature Class. '" + str(srcFC) + "' could not be acquired. Unable to continue. Contact GIS Manager.") # Acquire the Target Feature Class tgtFC = tgtGDB + "\\" + str(FD) + "\\" + str(TargetName) # Validate that the Target Feature Class was acquired, raising a Fatal Error if the Feature Class acquisition was unsuccessful if arcpy.Exists(tgtFC) == False: arcpy.AddError("An error occured while acquiring the target Feature Class. '" + str(tgtFC) + "' could not be acquired. Unable to continue. Contact GIS Manager.") # Delete the Target Feature Class from Disk arcpy.Delete_management(tgtFC) # Import the Source Feature Class into the Target Geodatabase, keeping the same name arcpy.FeatureClasstoGeodatabase_conversion(srcFC, tgtGDB + "\\" + str(FD)) # Reacquire the MXD's Feature Layer FeatureLayer = arcpy.mapping.Layer('"' + str(TargetName) + '"') # Update the MXD Feature Layer's Data Source FeatureLayer.replaceDataSource(str(tgtGDB), "FILEGDB_WORKSPACE", '"' + str(TargetName) + '"', True) # Save the Feature Layer to a Layer File, overwriting the existing target Layer File arcpy.SaveToLayerFile_management(FeatureLayer, tgtDIR + "\\" + str(TargetName) + ".lyr", "RELATIVE") """Cleanup""" # Delete the extraction folder arcpy.Delete_management(srcExtractDir) """If the name is 'COF_ATMs':""" elif name == "COF_ATMs": """Establish the Target Name""" TargetName = "COF_ATMs"
Solved! Go to Solution.
x = 1 if x < 5: print x """hi""" elif x > 5: print x
# Delete the extraction folder arcpy.Delete_management(srcExtractDir) """If the name is 'COF_ATMs':""" elif name == "COF_ATMs": """Establish the Target Name""" TargetName = "COF_ATMs"
# Delete the extraction folder arcpy.Delete_management(srcExtractDir) """If the name is 'COF_ATMs':""" elif name == "COF_ATMs": """Establish the Target Name""" TargetName = "COF_ATMs"
x = 1 if x < 5: print x """hi""" elif x > 5: print x
They get into this a bit on stack overflow, but I think the issue is you are using triple quotes interchangeably with comments, where a triple quote is really a doc string.
Also, why are you using """Strings as comments like this?"""