How do I fill a list in python with user-defined class instances?
<p>So I'm trying to fill a list with instances of a class that I defined myself, but I keep getting an error when I try to access any element in the list.  The code is below.</p>

<p>Any help would be appreciated!</p>

<pre><code>class Population:
"""total population of workers"""
    workerl = []

    def __init__(self, p, workers):
        # probability of a worker becoming unemployed
        # low in booms, high in recessions, could be a proxy for i
        self.p = p
        self.workers = workers
        workerl = []
        for i in range(workers):
            print i #test
            x = Worker()
            workerl.append(x)

p = 0
workers = 0

def showUR():
    """displays number of unemployed workers in a population"""
    ur = 0
    for worker in workers:
        if worker.isemployed == true:
            ur = ur + 1
    print ur

def advance(time, p):
    """advances one unit of time"""



# population as an array of workers     
class Worker:
    """a worker in a population"""
    isemployed = True

x = Population(.2, 100) 
print x.p
print x.workerl
if x.workerl[0].isemployed:
    print "worker 1 is employed"
</code></pre>
