0

I am trying to figure out why my ArcGIS Pro Python Script Tool with validation fails to open when I insert the block of code in my image.

def initializeParameters(self):
 shpFile = r"C:\LPA\Data\ne_10m_admin_0_countries.shp"
 self.params[0].filter.list = sorted([row[0] for row in
arcpy.da.SearchCursor(shpFile, "NAME")])
 return

enter image description here

user2856
73.7k7 gold badges123 silver badges207 bronze badges
asked Jul 18, 2023 at 17:55
0

1 Answer 1

2

I think that it is the two extra spaces of indentation before your first return that is causing the problem.

Try this instead of the code that you have presented:

def initializeParameters(self):
 shpFile = r"C:\LPA\Data\ne_10m_admin_0_countries.shp"
 self.params[0].filter.list = sorted([row[0] for row in arcpy.da.SearchCursor(shpFile, "NAME")])
 return

In a comment you showed a misspelt line of code that was giving a different error:

self.params[0].filter.list = sorted( [row[0] for row in arcpy.da.SearchCursur(shpFile, "NAME")])

should have SearchCursor (not SearchCursur):

self.params[0].filter.list = sorted( [row[0] for row in arcpy.da.SearchCursur(shpFile, "NAME")])
answered Jul 19, 2023 at 1:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.