I'm trying to write a python script to load feature class from an existing geodatabase to a new one, here is my script:

import arcpy
from arcpy import env
import os
import traceback

#Set up workspace
outworkspace = r"C:\user\Geodatabases\Gdb_mena_v3.gdb"
workspace = r"C:\user\Geodatabases\gdb_4.3.0_v2.gdb"

arcpy.env.workspace = workspace

#get a list of feature classes
featureclasses = arcpy.ListFeatureClasses()

for fc in featureclasses:

    shp_file = fc

    if shp_file == "MAP":
    arcpy.Append_management(os.path.join(workspace, shp_file), "C:\\user\\Geodatabases\\Gdb_mena_v3.gdb\\MAP", "NO_TEST", "","")

    print('Your load is done')

    else: print('Error reading data')
print "Finished!"

when I run the script I get this message:

 Error reading data
 Error reading data
 Error reading data
 Error reading data
 Error reading data
 Your load is done
 Error reading data
 Error shape file did not get read

Note that in my first geodatabase I have 7 features classes

  • Welcome to GIS SE, are you indenting after your if statement, if shp_file == "MAP":? – artwork21 Jun 22 '16 at 12:43
  • @artwork21, Yes – Hchliyah Jun 22 '16 at 12:52
  • I don't think this will help, but I don't think you need to join your workspace to your shp_file as you have already set your env.workspace variable. You could do os.path.join on your out fc though. os.path.join(outworkspace,"MAP") – JamesLeversha Jun 22 '16 at 12:54
  • Your error message does not necessary mean an error has occurred, rather just the "MAP" fc was not found. Looks like your fc was found on the 6 iteration. Do you have a fc named "MAP" in the other destination gdb to append to? – artwork21 Jun 22 '16 at 12:57
  • @artwork21, I think the my "MAP" fc was found , i checked the new gdb and the feature class "MAP" was appended – Hchliyah Jun 22 '16 at 13:19

As my comment noted, your code logic is correct, just your error messaging may of been misleading "Error reading data". "Error reading data" could be renamed to "other fc found: {}".format(shp_file) or just remove the entire else condition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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