1

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?

1 Answer 1

3

row.getValue(field_name)

See Accessing data using cursors in the help.

4
  • 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, 2011 at 23:07
  • Nope. row.fld would look for a field named "fld".
    – blah238
    Nov 5, 2011 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, 2011 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, 2011 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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