I'm trying to use arcpy.CalculateField in a script where I'm setting a "short" field to basically "(int(TransSeriesNo) * 100) + !OID!"
I have tried many incarnations of this based on the help docs and various geonet and other threads with no luck. I have success if I hardcode the the first part of the equation (ie. "int('!OID!') + 400") but of course that is not what I want to do. Below are some of the various things I have tried....the error message, if there is one, is in the comment above the set.
by the way, I know I can .format the better ( Curtis Price ) and will, but just trying to get it working first. Thanks for any help
#works
TransSeriesNo = "4"
setNo = (int(TransSeriesNo) * 100)
expression = "int('!OID!') + 400"
arcpy.CalculateField_management("Pts1c", "testID", expression , "PYTHON_9.3")
# doesn't work NameError: name 'setNo'is not defined
TransSeriesNo = "3"
setNo = (int(TransSeriesNo) * 100)
expression = "int('!OID!') + setNo"
arcpy.CalculateField_management("Pts1c", "testID", expression , "PYTHON_9.3")
# doesn't work NameError: name 'setNo'is not define
TransSeriesNo = "2"
setNo = (int(TransSeriesNo) * 100)
codeblock = "setNo"
expression = "int('!OID!') + setNo"
arcpy.CalculateField_management("Pts1c", "testID", expression , "PYTHON_9.3", codeblock)
# doesn't work NameError: name 'setNo'is not define
TransSeriesNo = "1"
setNo = (int(TransSeriesNo) * 100)
expression = "getPtID(setNo, !OID!)"
codeblock = """def getPtID(setNo, theOID):
setPtID = int(theOID + setNo)
return setPtID"""
arcpy.CalculateField_management("Pts1c", "testID", expression , "PYTHON_9.3", codeblock)