Author Arturo Inzunza
Recipients Arturo Inzunza
Date 2018-12-08.00:26:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1544228806.94.0.788709270274.issue35439@psf.upfronthosting.co.za>
In-reply-to
Content
List type variables in a class are not reset on new instances of the class.

Example: 

class Klazz:
    lst = []
    def __init__(self, va):
        print(self.lst)
        self.lst.append(va)


k = Klazz(1)
[]      -> This is correct as the lst value is empty on class instantiation

k2 = Klazz(2)
[1]   -> This is wrong, a totally new instance of the class retains the value of a previous class instance lst variable

k3 = Klazz(3)
[1, 2]  -> And so on... new instances all share the same list
History
Date User Action Args
2018-12-08 00:26:46Arturo Inzunzasetrecipients: + Arturo Inzunza
2018-12-08 00:26:46Arturo Inzunzasetmessageid: <1544228806.94.0.788709270274.issue35439@psf.upfronthosting.co.za>
2018-12-08 00:26:46Arturo Inzunzalinkissue35439 messages
2018-12-08 00:26:46Arturo Inzunzacreate