1

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.

1
  • 1
    What exactly isn't working here? Commented Oct 8, 2013 at 5:53

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. So the parameter can be anything we want it to be ?
2

You can create an instance of this class by doing

def addUser(self,User):

    myUser = User()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.