E
EP
Hi,
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=""):
self.name=myname
self.sex=mysex
def changeSex(self, newsex=""):
self.mysex=newsex
return self.mysex
def changeName(self, newname=""):
self.name=newname
return self.name
def whoAmI(self):
return self.name, self. sex
('Eric', 'Male')
[while it is comforting to know my sex isn't so easily changed, this
has confounded me in real code]
thx,
Eric
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=""):
self.name=myname
self.sex=mysex
def changeSex(self, newsex=""):
self.mysex=newsex
return self.mysex
def changeName(self, newname=""):
self.name=newname
return self.name
def whoAmI(self):
return self.name, self. sex
('Eric', 'Male')
('Jimbo', 'Male')'Jimbo'
('Jimbo', 'Male')'female'
[while it is comforting to know my sex isn't so easily changed, this
has confounded me in real code]
thx,
Eric