Cursor Object Oriented Programming stuff
This is a helper class to use with arcpy.da cursors, like SearchCursor and UpdateCursor.
Using arcpy cursors usually goes something like this...
feature_class = r'd:\foo\bar.gdb\buildings'
fields = [
'Name',
'Vacancy',
'Offices',
'OfficesAvailable',
'OfficesOccupied',
'Banner'
]
# known - Name, Offices, OfficesOccupied
# calculate - OfficesAvailable, Vacancy, Banner
with arcpy.da.UpdateCursor(feature_class, fields) as cursor:
for row in cursor:
row[3] = row[2] - row[4]
if row[3] < row[2]:
row[1] = True
row[5] = f'{row[0]}: {row[3]} Offices Available'
else:
row[1] = False
row[5] = f'{row[0]}: Offices Unavailable'
cursor.UpdateRow(row)
That is hard to follow. If the list of fields gets passed in a different order then the logic no longer works either.
Here is an alternative using this Feature helper class...
with arcpy.da.UpdateCursor(feature_class, fields) as cursor:
for row in cursor:
blg = Feature(fields, row)
blg.OfficesAvailable = blg.Offices - blg.OfficesOccupied
if blg.OfficesAvailable < blg.Offices:
blg.Vacancy = True
blg.Banner = f'{blg.Name}: {blg.OfficesAvailable} Offices Available'
else:
blg.Vacancy = False
blg.Banner = f'{blg.Name}: No Office Vacancies'
cursor.UpdateRow(blg.vals_to_tuple())
When arcpy graduates to Python 3.7, dataclasses may be the better alternative.