Hello everyone,
I am changing in my program the arcpy.SearchCursor to arcpy.da.SearchCursor and when I run the code I am getting the following error message:
Python Error occurred
'tuple' object has no attribute 'getValue'
# Get field objects from source FC AGREEMENT # dsc = arcpy.Describe(AGREEMENT) fields = dsc.fields # # List all field names except the OID field # fieldnamesYesterday = [field.name for field in fields if field.name != dsc.OIDFieldName] curYesterday = arcpy.da.SearchCursor(AGREEMENT, fieldnamesYesterday) for rowYesterday in curYesterday: agreementID = rowYesterday.getValue("AGMID") datetimeVal = rowYesterday.getValue("DIGIDATE") print agreementID print datetimeVal
indentation errors if that is what you have
This is a matter of simply reading the help files. The two different cursors use different syntax.
First read this:
ArcGIS Help (10.2, 10.2.1, and 10.2.2)
Then read this:
ArcGIS Help (10.2, 10.2.1, and 10.2.2)
This will answer your question.
Hello everyone,
I am following this sample to list all the fields:
What is wrong with my code, could you please be more specific.
Thanks
Hi Jose,
You need to reference the fields using their list index. For example, if AGMID is the 1st field, and DIGIDATE is the 3rd field, your code would be:
for rowYesterday in curYesterday: agreementID = rowYesterday[0] datetimeVal = rowYesterday[2] print agreementID print datetimeVal
Are you following the code in the SE thread because that is what you are doing, i.e., inserting records from one dataset into another, or are you using the code just for its general structure? If the former, it might be quicker to use either the Copy Features tool or Append tool.
The samples from ESRI always show a hardcoded list of fields ['fieldA', 'fieldB'] but in my case I need to read all the fields from the feature class, and list them in the "field_names" parameter.
arcpy.da.SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
See example 2 ListFields—Help | ArcGIS for Desktop
Here is the code you need:
# Get field objects from source FC AGREEMENT # dsc = arcpy.Describe(AGREEMENT) fields = dsc.fields # # List all field names except the OID field # fieldnamesYesterday = [field.name for field in fields if field.name != dsc.OIDFieldName] curYesterday = arcpy.da.SearchCursor(AGREEMENT, fieldnamesYesterday) for rowYesterday in curYesterday: agreementID = rowYesterday[fieldnamesYesterday.index("AGMID")] datetimeVal = rowYesterday[fieldnamesYesterday.index("DIGIDATE")] print agreementID print datetimeVal