-1

I am Trying to turn a list elements to a class instance. I have a list like the one below

new_value = ('TafaTIC', 'normal_user', '1', '19', False)

and a class just like this example

class student:
    def __init__(self, name: str, level: str, ID: str, age: str, student: bool):
        self._name = name
        self._level = level
        self._id = ID
        self._age = age
        self._student = student

basically what I want is to distribute these element to this class in order to be like this in the end

Student = student('TafaTIC','normal_user','1','19',False)

Thank you in advance <3

  • 1
    Terminology note: *everything* is a "class object" in Python, in the sense you are using it. The term you are looking for is *instance of a class*. A "class object" is the *class itself*. – juanpa.arrivillaga Dec 27 '22 at 22:02
  • 1
    Maybe [named tuples](https://docs.python.org/3/library/collections.html#namedtuple-factory-function-for-tuples-with-named-fields) are what are you looking for. – fen1x Dec 27 '22 at 22:04

1 Answers1

2

Just do:

Student = student(*new_value)

It should give the following:

print(Student._name)  # prints 'TafaTIC'
print(Student._level)  # prints 'normal_user'
print(Student._id)  # prints '1'
print(Student._age)  # prints '19'
print(Student._student)  # prints False
Saggy
  • 75
  • 7