[Tutor] a class knowing its self

Ben Vinger benvinger at yahoo.co.uk
Thu Jan 19 01:02:35 CET 2006


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']

python = Skill()
print python.getName()

for s in SkillNames:
  s = Skill()
  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


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