I have a code looks like this
rows = arcpy.UpdateCursor(featureClass) row = rows.next() #AddressFieldName = "ADD_FULL" while row: s= row.ADD_FULL
I'd like to use the field name as variable but if I wan to try like:
s=row. + AddressFieldName
or such thing that I can think of won't work.
Is there any way that I can use it as variable?
Solved! Go to Solution.
Wes Miller is right you should look into using the faster da cursor. If you want to continue using the cursor you are using then rather than accessing the field name directly as you have use this approach:
myField = "ADD_FULL" # You can change this to what ever field name you want rows = arcpy.UpdateCursor(featureClass) row = rows.next() while row: s= row.getValue(myField) print s row = rows.next()
Try using the da cursor it's easier to understand.
edit:
For your current code on line 5 s will now hold the attribute from your "ADD_FULL" field of the first record in your feature class table.
if you add the below it should print the attribute of every record in your feature class
rows = arcpy.UpdateCursor(featureClass) row = rows.next() #AddressFieldName = "ADD_FULL" while row: s= row.ADD_FULL print s row = rows.next()
Wes,
I was trying to get the field name in separate variable.
so I can received different field name from toolbox.
I don't understand what your after did you want to move the data to another field or maybe use another field to manipulate the data? To get another field in the method your using you would just do x = row.someotherfield then s+x would equal the values of s and x. If you give me more details or an example I could help you better.
I think I explained it wrong.
So, simply I was trying to use a variable to indicate a name of filed (column name)
define,
AddressFieldName = "ADD_FIELD"
then that field name has to be in
variable name s
but originally it works if I declare as (field[column] name ADD_FIELD)
s=row.ADD_FIELD
however I want to use ADD_FIELD as variable
s=row+ "." + AddressFieldName
this returns error
or any other ways that I can think of.
Wes Miller is right you should look into using the faster da cursor. If you want to continue using the cursor you are using then rather than accessing the field name directly as you have use this approach:
myField = "ADD_FULL" # You can change this to what ever field name you want rows = arcpy.UpdateCursor(featureClass) row = rows.next() while row: s= row.getValue(myField) print s row = rows.next()
Duncan,
almost miss your reply
I'll try it.
Thanks