Object containing a list of objects.

Peter Otten __peter__ at web.de
Sat Aug 28 14:02:40 EDT 2010


cocolombo wrote:

> Problem is that all instances of class tests have the same value.
> 
> To illustrate:

> class tests(object):
>     listOfTest = []

This makes listOfTest a class attribute. To get one list per instance define 
it in the initializer:

class Tests(object):
    def __init__(self):
        self.tests = []

Peter



More information about the Python-list mailing list