I have a decorator that currently requires each function that uses it to have a few arguments, arg1, arg2, and arg3. It works fine.
But one of the args in particular feels extraneous in that the functions don’t really want to have it as an input, e.g. for something like
@sql_decorator
def user_records(table, user, limit):
"sql to select records from ' + table + ' with user=%s limit %s" % (user, limit)
user and limit make sense as inputs, but table does not because the caller never has control over that. It feels extraneous.
Is there a way to do something like this:
@sql_decorator
def user_records(user, limit):
"sql to select records from table with user=%s limit %s" % (user, limit)
and then have the decorator change the sql by finding the instance of table and changing it to the right value?
If I understand you correctly, then you have something like this:
If so, then this is probably what you want:No, wrong answer. See below.[edit] According to your comment you probably want something like this: