0

I'm working with ArcGIS 10.2. I'm using the next Python code to show some records of an attribute table:

import arcpy
arcpy.MakeFeatureLayer_management(r"F:ArcGIS\Trab\Model\Lin_150_tr.shp", "lyr5")  
arcpy.SelectLayerByAttribute_management("lyr5", "NEW_SELECTION", """FID IN (2,10,200,323,349,384,433)""") 

But I'm not able to run my Python script again because appears an error like "lyr5 already exists". So I use a funtion: arcpy.Delete_management(lyr5) but it gives me an error NameError: name 'lyr5' is not defined.

  • What can I do to solve this problem, updating my layers, without loss my original shapefile called Lin_150_tr.shp?

  • May I do a copy of this shapefile before to do SelectLayerByAttribute?

1 Answer 1

1

You're quite close. The problem is that if you enter arcpy.Delete_management(lyr5) you tell python to delete a variable. You haven't saved your layer as a variable, this is why the error message shows up. Try this:

arcpy.Delete_management("lyr5")

or:

lyr5 = arcpy.MakeFeatureLayer_management(r"F:ArcGIS\Trab\Model\Lin_150_tr.shp", "lyr5") 
arcpy.Delete_management(lyr5)
2
  • When I try to do the same on a funcion arcpy.ExcelToTable_conversion("02_Re.xlsx", "c_re_otim.dbf", "Re_Lo") it's not possible.. It gives error.. How can I do?
    – S.Rai
    Aug 29, 2016 at 19:27
  • ok first of all it would be nice of you to give a feedback on the answer. did it work, did you encounter any other problems? as for your comment, this is a different topic, which requires a new question.
    – dru87
    Aug 31, 2016 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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