AnsweredAssumed Answered

cursor in a mosaic attribute table

Question asked by dschatt on Feb 20, 2018
Latest reply on Feb 20, 2018 by dschatt

hi all, I'm trying to update a Date type field ("Time") in a mosaic dataset attribute table with consecutive hourly increments.  The code worked fine with a snippet I used manually in the Field Calculator (.cal file).   Now I'm trying to put this same code in a stand-alone script and I'm getting a "Failed to check - syntax error - invalid syntax" error on the "row[1] = addHourIncrements(!OBJECTID!)" line.  Anybody know why?  Thanks!


import arcpy
from import *

import datetime

myMosaicDataset = "C:/stuff/test2.gdb/test"
#fields = ["OBJECTID", "Shape", "Raster", "Name", "MinPS", "MaxPS", "LowPS", "HighPS", "Category", "Tag", "GroupName", "ProductName", "CenterX", "CenterY", "ZOrder", "TypeID", "ItemTS", "UriHash", "Uri", "Shape_Length", "Shape_Area", "Time"]
fields = ["OBJECTID", "Time"]

with arcpy.da.UpdateCursor(myMosaicDataset, fields) as cursor:
    for row in cursor:
        row[1] = addHourIncrements(!OBJECTID!)
        #print row[1]
        #print type(row[1])

# Pull out present day and add one day, also extract OBJECTID value of first row to place in the [oid - _] position
def addHourIncrements(oid):
    startDataObj = datetime.datetime.strptime("06/19/2017 00:00:00", "%m/%d/%Y %H:%M:%S")
    return startDataObj + datetime.timedelta(hours=((oid - 1) * 1))