Use variable for field name in search cursor

794
1
Jump to solution
08-21-2012 08:56 PM
AnthonyCheesman1
Occasional Contributor II
Firstly, apologies for grammar and spelling, I am typing one handed and nursing a baby with the other.

I am looking for a way to use a variable as a field name for a search cursor, with the variable being drawn from another search cursor that runs down a dbf table.

The context is that the dbf table contains a list of themes that need to be queried, and also a list of fields in those themes that need to be reported.

I hope to pluck out the field names that need to be reported on and apply these to the search cursor running down the theme.

Any thoughts? I am currently using arcpy.getValue but it does not seem to be working.

Code snippet below:

if int(theme.REPFLD_NUM) == 0:                             pass                         elif int(theme.REPFLD_NUM) == 1:                             repfld1 = str(theme.getValue("REPFLD_1"))                             output_text.write(seltheme.repfld1 + "\n")                             del repfld1                         elif int(theme.REPFLD_NUM) == 2:                             repfld1 = str(theme.getValue("REPFLD_1"))                             repfld2 = str(theme.getValue("REPFLD_2"))                             output_text.write(seltheme.repfld1 + " - " + seltheme.repfld2 + "\n")                             del repfld1, repfld2  and so on.


Would appreciate any suggestions.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
AnthonyCheesman1
Occasional Contributor II
Solved it myself. I think.

[output_text.write(str(seltheme.getValue(repfld1)) + " - " + str(seltheme.getValue(repfld2)) + "\n")

View solution in original post

0 Kudos
1 Reply
AnthonyCheesman1
Occasional Contributor II
Solved it myself. I think.

[output_text.write(str(seltheme.getValue(repfld1)) + " - " + str(seltheme.getValue(repfld2)) + "\n")
0 Kudos