0

My code is like this:

class XQ(object):
def _XP(x, rettype='string'):
    @staticmethod
    def wrapper(*args, **kwargs):
        print "args: ", str(args)
        print "x: ", x
    return wrapper

something = _XP('adios')

and I do:

j = XQ()
j.something(5)

and the output is:

args:  (5,)
x:  adios

I do not understand how args gets to that value in the wrapper function, when _XP only has two arguments. I understand the use of * args and * kargs (I think), but I do not know how I received the inner function.

That 5 is not 'x', nor 'rettype' and I do not know how it reaches the other function

Could someone explain?

  • Don't you understand the syntax of `*args` or don't you understand inner functions? – Daniel Jan 04 '17 at 11:56
  • The second, probably. – Juan Alvarez Fernandez Jan 04 '17 at 15:59
  • ...it *doesn't* get assigned in the wrapper function (which is named `_XP`) at all. The `5` is only available in the inner function (named `wrapper`), because... well... you passed it as an argument to the inner function when you called it. Having names that are inverse of the actual roles of the two functions probably isn't helping anything with respect to understanding. – Charles Duffy Jan 04 '17 at 16:01

0 Answers0