[Tutor] class attribute to initiate more classes

Vincent Davis vincent at vincentdavis.net
Sat Oct 31 06:01:31 CET 2009

I have a program that generates many instances of a class with an attribute
self.x = random.gauss(10, 2). So each instance has a different value for
self.x. This is what I want. Now I want to make a class that starts my
program and sets the attributes.
class people:
    def __init__(self, size)
        self.size = size

class makepeople:
    def __init__(self, randomsize)
        self.rsize = randomsize
        self.allpeople = []
    def makethem():
        for x in range(1,100):
            p+str(x) = people(self.rsize)

so what I would like to have work is set the attribute of makepeople so that
when it is used to make instances of people each will have a different size.

listofp = makepeople(random.guass(100, 2))

I would then what listofp.allpeople to be a list of people with different
sizes. The above code does not work, I don't think it does anyway.

I hope this makes sense, I am sure there is a term for what I am trying to
do but I don't know it.

Vincent Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091030/427d9739/attachment.htm>

More information about the Tutor mailing list