I have a model that I would like to use the the following code to update a field "Permits" based on how many text occurrences are in "ParcelNum1" field based on the "PermitNum" field. I get the following error and need help figuring out what the issues is and all fields are text fields. I need this in model builder.
Example
OBJECTID | PermitNum | ParcelNum1 | Permits |
1 | aa1123 | 12345 | 12345, 12346 |
2 | aa1123 | 12346 | |
3 | BB3361 | 67891 | 67891, 67892, 37893 |
4 | BB3361 | 67892 | |
5 | BB3361 | 67893 | |
6 | UU9832 | 11123 | 11123 |
7 | PP2225 | 6989 | 6988, 6989 |
8 | PP2225 | 6988 |
Pre-Logic Script code:
dict1 = dict()
with arcpy.da.SearchCursor('TableTest6',['ParcelNum1','Permit_Count','PermitNum']) as cursor:
for row in cursor:
if row[0] not in (None, "", " "):
dict1.setdefault(row[0],[]).append(str(row[2]))
def concat(nf):
x = None
if nf in dict1t:
x = ",".join(dict1[nf])
return x
Permits = conact(!ParcelNum1! )
Error.
ERROR 000539: Runtime error
Traceback (most recent call last):
File "<string>", line 2, in <module>
RuntimeError: cannot open 'TableTest6'
Failed to execute (Calculate Field (4)).
Funny, I thought I posted the below post earlier, but was still sitting as draft....
Still having issues with TableTest6.
have you tried hard coding the path to that table?
with arcpy.da.SearchCursor(r'C:\path2table\TableTest6',['ParcelNum1','Permit_Count','PermitNum']) as cursor:
You can open the python window from Catalog and enter each command one at a time.
Can print individual variable results, etc. This can often give you more info on where it is failing.
R_
Documentation for model builder says that items in the drop-down (TableTest6) is a variable.
You could try putting it in the cursor as a variable instead of text:
with arcpy.da.SearchCursor(TableTest6,['ParcelNum1','Permit_Count','PermitNum']) as cursor:
and see if that works.
Otherwise, just hardcode the path and you are don.
R_