How to create and set variables as classes from a list of tuples?
<p>I am trying to figure out how to create variables from a list of tuple and assign them to a class. </p>

<p>I have data organized like this</p>

<pre><code> Name  Age  Status
 John  30   Employed
</code></pre>

<p>That I have created a list of tuple like this</p>

<pre><code> employeelist = [(John, 30, Employed), (Steve, 25, Part-Time)]
</code></pre>

<p>And a class set up like this </p>

<pre><code>class Employee():
ecount = 0
elist = []

def __init__(self, name, age, emp_status):
    self.name = name
    self.age = age
    self.emp_status = emp_status
    self.lookup = {}
    Employee.ecount = Employee.ecount+1
    Employee.elist.append(self.name)
</code></pre>

<p>Using this code I am able to turn the tuple into an instance of the class</p>

<pre><code> for i in range(0, len(employeelist),1):
    sublist = [str(n) for n in employeelist[i]]
    Employee(sublist[0], sublist[1], sublist[2])
</code></pre>

<p>But I am not able to access them. Is there a way to think about setting up the for loop to create a variable from sublist[0] and then create a class out of it (e.g. sublist[0] = Employee(sublist[0], sublist[1], sublist[2]))?</p>

<p>You just need</p>

<pre><code>employees = [Employee(*v) for v in employee_list]
</code></pre>

<p>Note that <code>employees</code> and <code>Employee.elist</code> are essentially the same once
each <code>Employee</code> object has been created.</p>

python class loops tuples