-1

I need to call a function method complete_login:

class VKOAuth2Adapter(OAuth2Adapter):  
    ...

    def complete_login(self, request, app, token, **kwargs):
    ...

It should be really easy, but i cant understand what parameter should be send in "self". I know why its there, but how to call such method?

login = VKOAuth2Adapter.complete_login( ??? , request, app, token)

Thanks.

Harkonnen
  • 149
  • 3
  • 11

2 Answers2

7

You need to make an instance of the class:

v = VKOAuth2Adapter( whatever parameters it needs, if any )

and then you'll call:

v.complete_login(request, app, token)

where v will automatically become the method's self.

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
4

The self parameter is usually not passed explicitly when calling a Python method--it is implicit. So you'd do this:

vk = VKOAuth2Adapter()
vk.complete_login(req, app, token)

The vk instance will be passed as self. You could write the code this way too:

vk = VKOAuth2Adapter()
VKOAuth2Adapter.complete_login(vk, req, app, token)

But that would not be considered normal practice in Python, so use the first option.

Note that if you are calling the method from inside another method in the same class, you'd do it this way:

self.complete_login(req, app, token)

That's because self would be an instance of the class, just as vk was in my previous examples.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436