johans11

General Python Question - Insert Variable into Variable?

Discussion created by johans11 on Mar 8, 2012
Latest reply on Mar 8, 2012 by mzcoyle
How do I insert a variable into a variable in Python? What I mean by that is if I want to do a cursor search based on a user specified field name i.e.

field_name = arcpy.GetParameterAsText(0)
input_table = arcpy.GetParameterAsText(1)

row, rows = None, None 
rows=arcpy.UpdateCursor(input_table)
Count = 1
for row in rows:
    row.field_name = Count #i.e. row. + field_name - if field_name = ID           search for row.ID
    Count = Count + 1
    rows.updateRow(row)
del row
del rows


Now I've tried to insert by making another variable and calling using
search = row.field_name
search = row + . + field_name #Returns syntax error¨
search = row. + field_name #Returns syntax error

What I need is something similar to string insertion like x = ('This is test # %s') %(3)) but for variables?

Any help would be apprecaited,
J

Outcomes