The script I am writing is simply to query multiple fields based on certain criteria and then assign a value to another field. I have multiple queries that need to be built. This is just the beginning as I am stepping into it slowly. This is literally the first script I've tried to write. I started working in Pro 2.4 which is where I am getting the TypeError. I tried it in ArcMap 10.5.1 and it ran fine. After researching a bit, I think it has something to do with changes between Python 2 and 3 but I am not sure. Field 0 is a short data type, Field 1 is a long data type and Field 2 is text.
If anyone has a suggestion on how to make it work in Pro, I would appreciate it.
fc = r"K:\PHYS\PROJECTS\LTSTest.gdb\Streets" fields = ['LOCAL_SPEED_MPH', 'AADT_NBR', 'TestLTS'] with arcpy.da.UpdateCursor(fc,fields) as cursor: for row in cursor: if (row[0] <= 25 or row[1] <= 1500): row[2] = 1 elif (row [0] > 40): row[2] = 2 cursor.updateRow(row) print("Done") # Traceback (most recent call last): # File "<string>", line 3, in <module> # TypeError: '<=' not supported between instances of 'NoneType' and 'int'
Solved! Go to Solution.
You hit a null value in your table, you have to skip those records
for row in cursor: if row[0] is Null: continue if (row[0] <= 25 or row[1] <= 1500):
/blogs/dan_patterson/2016/08/14/script-formatting will help with formatting and line numbers
You hit a null value in your table, you have to skip those records
for row in cursor: if row[0] is Null: continue if (row[0] <= 25 or row[1] <= 1500):
/blogs/dan_patterson/2016/08/14/script-formatting will help with formatting and line numbers
Thanks for the quick reply and formatting help (I couldn't figure out how to do it in the first post).
I added the code you suggested but it came back as "NameError: name 'Null' is not defined" so I changed it to None which seemed to go through. Now, it's back to the same error as before.
Sorry, it should have been None..
So that suggests that there is None in your other field so try
if row[0] is None or row[1] is None:
or
if None in row: # think this should work,
In fact, just open the table and query your field for <null> (aka, None), to see what you are dealing with
Had to think a little bit (I'm taking baby steps with this...) but yes, it did work once I realized I needed to use row[1] instead of 0 because that is where some null values are. Thanks again for the help.