[BangPypers] class instance getting passed to other class obj creation

Gora Mohanty gora at mimirtech.com
Sun Mar 9 13:02:15 CET 2014


On 9 March 2014 16:37, Nitin Kumar <nitin.nitp at gmail.com> wrote:
>
> Hi All,
>
> I am looking for some better way to implement below scenario.
>
> Say there is a class login
>
> class login:
> def __init_(self, user, pwd):
> -----
>
> now user uses this class to login a session and then I am using the object
> of this class being passed to other class. So that other class can use this
> logged in session.
>
> >>> lgn = login()
> >>> scores(lgn)
> >>> account(lgn)
>
> I am somehow not in favour of passing this object to different class. Is
> there a way such that once we have login object that is visible to other
> class.

How does your login work? What does the class store in order to validate
login? Nowadays, this is typically an authentication token obtained with
OAuth2, or the like. So, you could pass lgn.token to other functions that
need authenticated services, though that is not very different from passing
lgn itself.

What is your objection to passing the login class instance? Alternatively,
all services needing authentication could be part of a single class, where
login() is a class method or derived from a base class.

Regards,
Gora


More information about the BangPypers mailing list