0

I just came across to this code , I know how variable length parameter works but i am confuse with this line func(*((userId,)+pargs)

def pwapi_auth(func):
    def inner(authToken, *pargs, **kwargs):
        # ...
        users = {'a':0,
                 'b':1,
                 'c':2}
        userId = users[authToken]
        return func(*((userId,)+pargs), **kwargs)
    return inner
>>> print getUsername('b')
Name_2
>>> changeUsername('b', 'New_Person')
>>> print getUsername('b')
New_Person
  • @Martijn Pieters , its not duplicate , please read my question , I asked how (*((userId,)+pargs) works , I know how asterisk work and what *args do but i am asking how this (+) and this line works ((*((userId,)+pargs) –  Oct 09 '16 at 14:49
  • `(userId,)` is a tuple. It is added to another tuple named `pargs`. The result is a tuple passed in with `*`. – Martijn Pieters Oct 09 '16 at 14:50
  • 1
    @Baap It's prepending `userId` to the list `pargs`. It's roughly like `func(userId, *pargs)`. Not sure why the authors did that... – kirbyfan64sos Oct 09 '16 at 14:51

0 Answers0