Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have code that says

fld = fieldName 
rows = arcpy.SearchCursor(fc)
for row in rows:
    x = row.fld

How do I use a variable for my field name in python ArcGIS 10 on windows? Thanks.

share|improve this question

1 Answer

up vote 2 down vote accepted

row.getValue(field_name)

See Accessing data using cursors in the help.

share|improve this answer
I just found that in some older code I wrote. Thanks..but say I did not want to use the getValue method..is it possible using row.fld? – Justin Nov 5 '11 at 23:07
Nope. row.fld would look for a field named "fld". – blah238 Nov 5 '11 at 23:09
Not to pester but I get that..so row is an object??..looking for a what and how could....ah nevermind..I guess that is why they put the getValue method in there..Thanks! – Justin Nov 5 '11 at 23:13
Yes, it's a Row object. arcpy uses some voodoo to go between ArcObjects and Python objects, you can step through it in a Python debugger to see it in action. – blah238 Nov 5 '11 at 23:25
P.S. - You can improve your accept rate by accepting answers! People are more likely to answer if your accept rate is high. – blah238 Nov 6 '11 at 0:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.