[PYTHON] Decorator that checks variable names and changes behavior

It may not be very practical (my practice + memo substitute)

def deco(func):
    from inspect import getargspec
    def inner(*args, **kwargs):
        arg = getargspec(func)
        if 'a' in arg.args:
            print args[arg.args.index('a')];
        return func(*args, **kwargs)
    return inner

What this sample is doing is to display the value of the argument named'a'if it is included in the args argument. If the method signatures are similar to some extent, do you apply a decorator for a particular method? Created instead of inspect practice.

Recommended Posts

Decorator that checks variable names and changes behavior
Recommended tf.keras custom layer writing and variable name behavior