Behavior of mutable class variables

tkpmep at hotmail.com tkpmep at hotmail.com
Wed May 9 18:49:49 EDT 2007


Thanks for the insights. I solved the problem as follows: I created a
new class method called cleanUp, which resets NStocks to an empty list
and N1 to 0. Works like a charm - it's the first time I've used a
class method, and I immediately see its utility. Thanks again

class Stock(object):
    NStocks = []             #Class variables
    N1         = 0

    @classmethod
    def cleanUp(cls):
        Stocks.NStocks = []
        Stocks.N1 = 0



def simulation(N, par1, par2, idList, returnHistoryDir):

    Stock.cleanUp()
    results = ......
    print results.






More information about the Python-list mailing list