AnsweredAssumed Answered

update cursor won't update

Question asked by wws_ahargreaves on Sep 12, 2018
Latest reply on Sep 12, 2018 by bixb0012

Hi All,

This seems to be a common topic, but I've still not found an answer. I have the below code, which executes without error. However, the values are not updated. What am I doing incorrectly with my cursor?

 

 

import arcpy, os, getpass, datetime
from datetime import datetime, timedelta

 

# name of the fGDB
fGDB = "xxxxxxxxx.gdb"

 

# Local folder where the data was downloaded (include slash at the end)
download_folder = "C:/Users/xxxxxxxx/"

 

# Set geoprocessing environment:
arcpy.env.workspace = download_folder + fGDB

 

# Set geoprocessing environment:
arcpy.env.overwriteOutput = True

 

#Get the Current date and time...
now = datetime.now()

 

try:

 

# Set Variables
fcList = arcpy.ListFeatureClasses() #Get fc's in GDB
dateOp = now
utcOffset = 0

 

for fc in fcList: # Iterate through feature classes
   fieldList = arcpy.ListFields(fc) # get all fields
   rows = arcpy.UpdateCursor(fc)

for row in rows:

dateOp = row.getValue("DATETIME_OPERATED")
utcOffset = row.getValue("UTC_OFFSET")
print "Date operated: " + str(dateOp)
print "UTC Offset: " + str(utcOffset)

utcOffsetTime = (dateOp + timedelta(hours=utcOffset)) 
utcOffsetDateTimeStr = utcOffsetTime.strftime("%m") + "/" + utcOffsetTime.strftime("%d") + "/" + utcOffsetTime.strftime("%Y") + " " + utcOffsetTime.strftime("%H") + ":" + utcOffsetTime.strftime("%M") + ":00"
print "New time is: " + utcOffsetDateTimeStr
row.setValue("DATETIME_OPERATED", utcOffsetDateTimeStr) 
rows.updateRow(row)

 

except:

# Code to run when an error occured
print "An ERROR Occured!"
print "\n" + arcpy.GetMessages()


else:

# Message when there was no error
print "\nNo Error occurred"

# Script end message
print "\nEnd of the script!"

 

Thanks

Outcomes