AnsweredAssumed Answered

How do I insert a string into a prepared field?

Question asked by Sycosys on Oct 10, 2012
Latest reply on Oct 10, 2012 by clthompson
I turn to your wisdom once again. All I need this bit of code to do is run a field calc and insert the prepared string "hat".. everything I have tried this afternoon has failed. What i have tried is all manner of wrapping that string in double quotes, single quotes, no quotes, etc..

Any ideas what I'm doing wrong?

The area in question is down in the For loops. Everything up till that last line works fine.

arcpy.CalculateField_management("Temp_Stats", "Query", hat , "PYTHON")

import arcpy from arcpy import env  env.workspace = "C:/Users/atimpson/Desktop/PNG HCA Program Dev/PNG_Planning_Map.mdb"  clQuery = ["[CL_MAOP] = 1","[CL_MAOP] = 2","[CL_MAOP] = 3","[CL_MAOP] = 4"] hcaQuery = ["[UniqueID] IS NOT Null","[UniqueID] IS Null"] pressQuery =["[PRESSURE1] > 0", "[PRESSURE1] = 0"]   try:  arcpy.SelectLayerByAttribute_management ("Testing", "NEW_SELECTION", "[ObjectID]>=0")  arcpy.Statistics_analysis("Testing", "Stats", [["Shape_Length", "SUM"]])  arcpy.AddField_management("Stats", "Query", "TEXT", "", "", 100)  arcpy.CalculateField_management("Stats", "Query",'"[ObjectID] >= 0"', "PYTHON")    for cl in clQuery:   for hca in hcaQuery:    for press in pressQuery:        arcpy.SelectLayerByAttribute_management ("Testing", "NEW_SELECTION", cl + " and " + hca + " and " +  press)     hat = str(cl + " and " + hca + " and " +  press)     print hat     arcpy.Statistics_analysis("Testing", "Temp_Stats", [["Shape_Length", "SUM"]])     count = int(arcpy.GetCount_management("Temp_Stats").getOutput(0))     arcpy.AddField_management("Temp_Stats", "Query", "TEXT", "", "", 100)     arcpy.CalculateField_management("Temp_Stats", "Query", hat , "PYTHON")