AnsweredAssumed Answered

python in ArcGIS, need help!

Question asked by dzestis94 on Apr 25, 2017
Latest reply on Apr 27, 2017 by xander_bakker

Hello everyone,

So I started to work with ArcGis and Python. And I got a task.


This is what I have to do:


Check that all the objects have filled Glb_Cpy field. If found empty object, then this field has to be filled by Glb_ID value.


So I did it. But now I have to create statement, if fc doesn`t have Glb_ID or Glb_Cpy fields, then arcpy.AddError("Invalid Data") ->return and script stops.  else arcpy.AddMessage("Valid Data") and complete the script. I know that I`m thinknig that i need to use arcpy.Exists , arcpy.ListFields or arcpy.Describe ... I hope someone understood me.


Waiting any suggestions! Thanks!


import arcpy

def main(fc):

    desc = arcpy.Describe(fc)

    if desc:
        arcpy.AddError("Invalid Data")

        arcpy.AddMessage("Valid Data")
        with arcpy.da.UpdateCursor(fc, ['Glb_ID', 'Glb_Cpy'], 'Glb_Cpy IS NULL') as cursor:
        for row in cursor:
            row[1] = row[0]
            # Update the cursor with the updated list

if __name__ == "__main__":