--- title: "Python equivalents" --- def add1(x): return x+1 add1(3) def logargs(f): "Print arguments to `f` before calling it" def _inner(*args, **kwargs): print(f"Received: {args=}; {kwargs=}") return f(*args, **kwargs) return _inner def _mult2(x): return x*2 mult2 = logargs(_mult2) mult2(3) @logargs def mult2(x): return x*2 mult2(3) class logargs: def __init__(self, prefix='Received: '): self.prefix=prefix def __call__(self, f): def _inner(*args, **kwargs): print(f"{self.prefix}{args=}; {kwargs=}") return f(*args, **kwargs) return _inner def _add1(x): return x+1 o = logargs('Logging: ') add1 = o(_add1) add1(3) @logargs('Logging: ') def add1(x): return x+1 add1(3) from functools import partial def pow(x,y): return x**y pow(3,2) squared = partial(pow, y=2) squared(3)