Select to view content in your preferred language

Relative Field Values in For Loop

821
3
03-15-2012 01:45 PM
TomGiles
Deactivated User
My issue is trying to retrieve field values inside a for loop:

#userFile - type FeatureLayer
userFile = arcpy.GetParameterAsText(0)

#user selects field from userFile - type Field "obtained from [userFile]"
userField = arcpy.GetParameterAsText(1)

#start cursor
rows = = arcpy.SearchCursor(userFile)

#inside loop, report all values of field [userField]
for row in rows:
        arcpy.AddMessage("Analyzing zone " + row.userField)



Python wants userField to be a hard coded value for the field. It won't accept it as a variable set by the user. Any way I can accomplish this?

Cheers
Tom
Tags (2)
0 Kudos
3 Replies
MathewCoyle
Honored Contributor
row.getValue(variable)
0 Kudos
TomGiles
Deactivated User
Thanks Mathew - I knew it was too easy.
0 Kudos
DanPatterson_Retired
MVP Emeritus
Also Tom, you have == in the searchcursor line which won't work ... which I see you have now fixed
0 Kudos