Reputation: 16385
How can i pass object of one class to function parameters
class Login():
def __init__(self):
pass
def addUser(self,User):
pass
class User():
So in my code i want to pass the object of user to the addUser function of the login class? I am to Python.
Upvotes: 1
Views: 129
Reputation: 7931
You can create an instance of this class by doing
def addUser(self,User):
myUser = User()
Upvotes: 2
Reputation: 39548
Python is a dynamically typed language - your method signature does not care about the type of the parameter. So something like:
class Login(object):
def __init__(self):
pass
def addUser(self, user):
user.add()
class User(object):
def add(self)
self.set_password()
u = User()
l = Login()
l.addUser(u)
would work just fine.
Upvotes: 2