making objects with individual attributes!

Alejandro altudela at yahoo.com
Tue Mar 20 12:08:22 EDT 2007


I have created a class:

class document:

    titre = ''
    haveWords = set()

    def __init__(self, string):

        self.titre = string

#########

doc1 = document('doc1')
doc2 = document('doc2')

doc1.haveWords.add(1)
doc2.haveWords.add(2)


print doc1.haveWords

# i get set([1, 2])


doc1 and doc are sharing attribute haveWords!
Why ??? there's a way to assign every objetc "document" a different
"set"




More information about the Python-list mailing list