Someone enlightened me

Marcus Low marcus at internetnowasp.net
Sat Jul 12 22:08:22 EDT 2008


Can someone explain to me, why the behaviour below is different when u 
remark "lister" and unremark "self.lister"?

#--------------------------------------------------------------
class abc :
    # remark this later and unremark "self.lister"
    lister = []

    def __init__ (self, val):
        #self.lister = []
        self.lister.append(val)   

#--------------------------------------------------------------
globallist = []
#--------------------------------------------------------------    
def test () :
    global l
    for x in range(10) :
        o = abc(x)        
        globallist.append(o)           
        o = ""
  
    for i in globallist :
        print i.lister      

#--------------------------------------------------------------
test()        
#--------------------------------------------------------------
 




More information about the Python-list mailing list