I am trying to figure out how to format a text variable grabbed from a file geodatabase table and update another file geodatabase table field with this variable. The fields in both tables are text fields with a field size 300. The entire column is to be updated with the same value extracted from table1. I cannot seem to format var1 in the arcpy.CalculateField_management statement correctly.
A separate table is created for each row searched and an sql query built from values in row[2]. Using the sql, records are selected from a third table and saved with the file name grabbed from row[0]. Once the records are saved to this table, I add a new field and update it with the value from row[1]. All this is done correctly up to when I try to update the "Description" field. I am pretty sure it is a formatting issue.
the value from table1 grabbed via SearchCursor:
var = row[1]
I want to update the field "Description" in table2. I have tried the following formats:
var1 = var
var1 = '!' + var + '!'
arcpy.CalculateField_management("table2", "Description", var1, "PYTHON3")
var1 = '"' + var + '"'
arcpy.CalculateField_management("table2", "Description", var1, "PYTHON3")
arcpy.CalculateField_management("table2", "Description", "'" + var1 + "'", "PYTHON3")
I am stumped. I am at home and the code is a work which is why I did not include it. I think this enough to go by though. Any pointers would be greatly appreciated.
Using ArcMap 10.6.1
I'll assume from the quotes you are throwing around var contains a string. In which case you want :
arcpy.CalculateField_management("table2", "Description", "'" + var + "'", "PYTHON3")
Note that I used 'var' not 'var1'. If var contains a number you can simply do:
arcpy.CalculateField_management("table2", "Description", var, "PYTHON3")