Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The for loop below works without error, but the result is get in the table of my database is wrong. Its as if the for loop skips right over the first 3 if and elif statements and goes to the else. The table I am using has values 1 through 5 in each row of the WWFLOWDATA column and the data type is a number. Does anyone have any idea why its not giving me the output I am looking for? Maybe an issue with the access database?

import os  
import arcpy    
from arcpy import env

arcpy.env.workspace = r"C:\Users\sutton\Documents\Python\PythonExcercise\DuncanvilleData.mdb"


        #create new field to hold new values
        print("Rehab Field added to Wastewater_Lines")
        with arcpy.da.UpdateCursor("Wastewater_Lines",["WWFLOWDATA","PipeAssesment"]) as cursor:
            cntr = 1
            for row in cursor:
                #update the indicator field
                if row[0] == '5':
                    row[1] = "Critical"
                elif row[0] == '4':
                    row[1] = "Monitor"
                elif row[0] <= '3':
                    row[1] = "Unknown"
                    row[1] = "Unknown"

except Exception as e:

StatusofScript = "Script executed"
print StatusofScript
share|improve this question
up vote 5 down vote accepted

You said that the datatype of the DB column is a number, but in your if and elif statements you compare that number to a string (e.g. 4 == '4') which will return False. Maybe you get the desired result when you remove the single quotes around the numbers, for example:

row[0] == 4:

instead of

row[0] == '4':.

share|improve this answer
My mistake, that was something I was trying earlier. I have edited the post to reflect what I have more accurately. The problem is I am only getting "Unknown" as a result in the new column despite the other if statements. – Colin Mar 10 at 15:28
Try to open the dataset in ArcMap and try to access the same data through the Python window. Use a SearchCursor with the same parameters and print row[1]. This will help you get a handle on how Python is actually seeing your data. I think @TobsenB is on the right track - I bet if you remove the single quotes around the numbers, you'll get the right results. – Andy Bradford Mar 10 at 15:46
@Colin your post still demonstrates the mistake that Tobson described. Read his answer again. – Tom Mar 10 at 15:56
Thank you TobsenB – Colin Mar 10 at 16:02
You're welcome! In the first version of my answer I used the term parantheses instead of quotes - sorry if that led to confusions. – TobsenB Mar 11 at 7:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.