0

I have some function

def func(x, y)

and I want to write a decorator so that when I call it like so

func(a.b.c, d)

the input arguments are modified so that it's actually calling it like

func(a.b.c, a.b.c.d)

For this function specifically, I want the second argument to implicitly have the first argument pre-pended.

Bob
  • 4,576
  • 7
  • 39
  • 107
  • Can you please give a full example of what output you expect? What you are literally asking for is just impossible in Python. `d` is just a variable name that has nothing to do with `a.b.c.d`. Once you pass `d` into `func(x, y)` you just pass its value but the function doesn't even know that that variable is called `d`. If your're okay with passing the name to the function like so: `func(a.b.c, 'd')`, that would be pretty straightforward to implement. – Joooeey Jul 23 '18 at 15:14
  • I told you the output: when user types `func(a.b.c, d)`, I want the real call to be `func(a.b.c, a.b.c.d)`. This should be possible with decorators. – Bob Jul 23 '18 at 15:15
  • 1
    This thing exactly is virtually impossible: https://stackoverflow.com/questions/2749796/how-to-get-the-original-variable-name-of-variable-passed-to-a-function I guess fafl's answer should solve your problem. You just have to pass the property name as a string (`d`). – Joooeey Jul 23 '18 at 15:31
  • @Adrian what you're asking for is impossible, period. Sunitha's answer (alas deleted) was the closest you could get (and was properly implemented which is not the case of fafl's one) – bruno desthuilliers Jul 23 '18 at 16:51

0 Answers0