Class attributes newbie question (before I join a cargocult)

EP eric.pederson at
Sun Mar 12 13:36:15 EST 2006


This is likely a stupid question, but I am confused about what is going
on with class attributes as far as whether they "stick".  I ran across
this in a program I am writing, but have reproduced the behavoir below
- can someone point me in the right direction (thanks):

class AttStickiness(object):
    def __init__(self, myname="", mysex=""):

    def changeSex(self, newsex=""):
        return self.mysex

    def changeName(self, newname=""):

    def whoAmI(self):
        return, self. sex

>>> me=AttStickiness("Eric","Male")

>>> me.whoAmI()
('Eric', 'Male')

>>> me.changeName("Jimbo")

>>> me.whoAmI()
('Jimbo', 'Male')

>>> me.changeSex("female")

>>> me.whoAmI()
('Jimbo', 'Male')

[while it is comforting to know my sex isn't so easily changed, this
has confounded me in real code]



More information about the Python-list mailing list