Hi,To calculate the values in Field: "Start_time" using those in Field: "Period_Sta", I tried expression below. However it doesn't work. Can anybody help to debug it?ThanksIf [Period_Sta] =="01/01" Then [Start_time]= �??1�?�elseif [Period_Sta] == "01/04" Then [Start_time]= �??91�?�elseif [Period_Sta] == "30/09" Then [Start_time]= �??273�?�elseif [Period_Sta] == "31/12" Then [Start_time]= �??365�?�end if
gp.CalculateField_management(myFC, "Start_time", "returnvalue(!Period_Sta!)", "PYTHON", "def returnvalue(periodStaFieldValue):\\n if periodStaFieldValue == '01/01':\\n return '1'\\n elif periodStaFieldValue == "01/04":\\n return '91'\\n elif periodStaFieldValue == "30/09":\\n return '273' \\n elif periodStaFieldValue == "31/12":\\n return '365'")
updateRows = arcpy.UpdateCursor(myFC) for updateRow in updateRows: if updateRow.Period_Sta == '01/01': updateRow.Start_time = '1' elif updateRow.Period_Sta == '01/04': updateRow.Start_time = '91' elif updateRow.Period_Sta == '30/09': updateRow.Start_time = '273' elif updateRow.Period_Sta == '31/12': updateRow.Start_time = '365' updateRows.updateRow(updateRow) del updateRow, updateRows
If [Start_time] is defined as a numeric field, then you don't need the quotes around the value ([Start_time] = 1).
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.