[Tutor] a class knowing its self
Ben Vinger
benvinger at yahoo.co.uk
Thu Jan 19 01:02:35 CET 2006
Hello
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?
b returns:
<__main__.Skill instance at 0x401e260c>
<__main__.Skill instance at 0x401e230c>
<__main__.Skill instance at 0x401e23ec>
why does b not return the names of the 3 instances of
Skill?
Thanks
Ben
___________________________________________________________
To help you stay safe and secure online, we've developed the all new Yahoo! Security Centre. http://uk.security.yahoo.com
More information about the Tutor
mailing list