-1

The class( people ) requires 3 arguments called "name, middle_name and surname" and I am trying to give these arguments like down below:

    def argument():
        name = input("name : ")
        middle_name = input("middle name : ")
        last_name = input("last name : ")
        return name,middle_name,last_name
   person = people(argument())

But somehow its not working, the error message I am getting:

TypeError: __init__() missing 2 required positional arguments
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Dogukan
  • 89
  • 1
  • 6

3 Answers3

6

Assuming the following definition of people:

class people:

    def __init__(self, name, middle_name, last_name):
        self.name = name
        self.middle_name = middle_name
        self.last_name = last_name

This should work:

def argument():
    name = input("name : ")
    middle_name = input("middle name : ")
    last_name = input("last name : ")
    return name, middle_name, last_name


person = people(*argument())

print(person.name)
print(person.middle_name)
print(person.last_name)

Note the * before the call to argument argument(). This is known as unpacking

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76
3

You can use the star/explode notation to unpack them

person = people(*argument())

As a random tip, in Python, we typically Capitalize class names, so I'd recommend using something like a Person class instead of trying to differentiate classes and instances based on plurality (people vs person). Just do Person (the class) vs person (an instance).

Stephen C
  • 1,966
  • 1
  • 16
  • 30
2

argument function will return tuple. you need to unpack it in order to supply 3 positional arguments person = people(*argument())

buran
  • 13,682
  • 10
  • 36
  • 61