Hi,
I came across the use of decorators while watching YouTube videos on python, and I thought that there might be a way to utilize this to run the update cursor method without having to specify multiple functions or program it right off the bat. It seems to run this segment of code just fine, but I wanted to see if anyone else has done anything like this. Any examples that would be greatly appreciated.
# Python code to illustrate
# Decorators with parameters in Python
def decorator():
def inner(func):
print ('Starting edit process\n')
# Start edit operation
print (f'edit = arcpy.da.Editor({Database})')
print ('edit.startEditing(False, True)')
print ('edit.startOperation()\n')
func()
# Finish edit operation
print ('edit.stopOperation()')
print ('edit.stopEditing(True)\n')
print ('Finished edit process\n')
# returning inner function
return inner
@decorator()
def my_func():
s = ' '*4
print (f'with udpate as cursor:{s}')
print (f'{s}for row in cursor:')
print (f'{s*2}if row[tile] in {Dictionary}:')
print (f'{s*3}row[tile]=row[tile]')
print (f'{s*3}row[shape]={Dictionary}[row[tile]]')
print (f'{s*3}cursor.updateRow(row)\n')
Database = 'AFavorites\GIS.gdb'
Dictionary = 'ATest'