I'm using decorator with the functional syntax as it's described here.
I loop over a list of dict. In this loop I wrap a generic function with a decorator taking a parameter. Then i call the wrapped function with the current dict as parameters.
My problem is that i get an local variable 'generic_evaluator' referenced before assignment
error.
Here is my code:
The concerned decorator:
def log(logfile_name):
def inner_log(func):
def wrapped(*args, **kwargs):
import os
ret = func()
# business code...
return wraps(func)(wrapped)
return inner_log
And here the place where I wrap generic_evaluator
function with the log
decorator.
for evaluation in generic_evaluations:
generic_evaluator = log(evaluation['suffix'])(generic_evaluator)
generic_evaluator(evaluation['suffix'], evaluation['id'])
EDIT
It'll be probably more clear with this piece of code in addition:
@tictoc
def generic_evaluator(suffix_url, id):
xml = etree.parse(get_resource(base_url + "/" + suffix_url + "/" + str(id)))
links = fetch_urls_from_xml(xml)
return links