Error when running Search Cursor...HELP!

336
2
05-09-2022 06:47 PM
AndreaB121
New Contributor

I am receiving this error when running Search Cursor...HELP!

Error that is given:

Working on pour point 0

Traceback (most recent call last):
File "C:\Users\Chris\Desktop\Hawaii\hawaii_5.py", line 30, in <module>
cur_point = select_pour_point(POUR_POINTS, NAME_FIELD, name)
NameError: name 'select_pour_point' is not defined

 

Part from my code that is giving the error:

for point in arcpy.da.SearchCursor(POUR_POINTS, NAME_FIELD):
name = str(point[0])

print "Working on pour point %s" % (name)
cur_point = select_pour_point(POUR_POINTS, NAME_FIELD, name)
shed_raster = make_watershed_raster(FLOW_DIRECTION, cur_point, name, SCRATCH)

0 Kudos
2 Replies
Luke_Pinner
MVP Regular Contributor

Bit hard to say, you haven't shown enough code. Do you define or import the select_pour_point or make_watershed_raster functions anywhere?

BlakeTerhune
MVP Regular Contributor

You should review the documentation for cursors and use it in a with statement like this:

 

with arcpy.da.SearchCursor(POUR_POINTS, ["NAME_FIELD"]) as cursor:
    for point in cursor:
        name = str(point[0])
        print("Working on pour point {}".format(name))
        # Do stuff with data in cursor...

 

 

Also, as @Luke_Pinner mentioned, you need more of your code that shows where select_pour_point is defined. It must be defined before it is used.

0 Kudos