I am trying to create a script to add values to a new field in a table based on the text values of another field in the same table. Here is my code:
import os import arcpy from arcpy import env arcpy.env.workspace = "c:/Myfiles/geodatabase" updateFields = ["fieldname1","fieldname2"] def updateweight(filename,fields): with arcpy.da.UpdateCursor(filename,fields) as cursor: for row in rows: if row == "unrestricted": row = 3 elif row == "restricted": row = 2 elif row == "severely restricted": row = 0 Cursor.updateRow(row) del cursor updateweight("shape_file_name", updateFields)
When I run this I get:
Run time error File "<string>" line 1 in <module> File "<string?" line 11 in updateweight cannot open 'shape_file_name'
I've tried including the .dbf file extension in the file name and also tried calling the assigning a variable to the filename and calling it that way.
I was unable to copy and paste the code directly because it is on a work machine in a secure environment, so there my be some typos in the code. I wrote it as a function so I can make it into a more generic tool once I've tested it.