Ben, If you change example #b to:
for s in SkillNames: skill = Skill() skill.setName(s) print skill.getName() You will find that the results are the same as #a. In your #b example, you are giving setName() the skill instance instead of the string you intended. --Shuying On 1/19/06, Ben Vinger <[EMAIL PROTECTED]> wrote: > I've been reading about how a class has access to its > own 'self', so I tried the following, but it is not > working as I would expect: > > class Skill: > def __init__(self): > self.history = [] > > def setName(self, skill): > self.name = skill > > def getName(self): > return self.name > > # Assigning data to my class: > > SkillNames = [r'python', r'apache', r'mysql'] > > #a.) > python = Skill() > python.setName('python') > print python.getName() > > #b.) > for s in SkillNames: > s = Skill() > s.setName(s) > print s.getName() > > Why does a work and b not? _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor