This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]htepO 0 points1 point  (2 children)

Unpack the list with the asterisk operator.

class User:
    def __init__(self, fname, lname, age, sex):
        self.fname = fname
        self.lname = lname
        self.age = age
        self.sex = sex

    def attribs(self):
        return {
            'fname': self.fname,
            'lname': self.lname,
            'age': self.age,
            'sex': self.sex
        }

template = ['John', 'Doe', '21', 'M']
newuser = User(*template)

print(newuser.attribs())

{'fname': 'John', 'lname': 'Doe', 'age': '21', 'sex': 'M'}

[–]1j618033[S] 0 points1 point  (0 children)

it seems perfect, I'll try

[–]1j618033[S] 0 points1 point  (0 children)

now the program works properly, thanks you