Please help me understand this. I created a really simple program to try to understand classes.
class One(object):
def __init__(self, class2):
self.name = 'Amy'
self.age = 21
self.class2 = class2
def greeting(self):
self.name = raw_input("What is your name?: ")
print 'hi %s' % self.name
def birthday(self):
self.age = int(raw_input("What is your age?: "))
print self.age
def buy(self):
print 'You buy ', self.class2.name
class Two(object):
def __init__(self):
self.name = 'Polly'
self.gender = 'female'
def name(self):
self.gender = raw_input("Is she male or female? ")
if self.gender == 'male'.lower():
self.gender = 'male'
else:
self.gender = 'female'
self.name = raw_input("What do you want to name her? ")
print "Her gender is %s and her name is %s" % (self.gender, self.name)
Polly = Two()
Amy = One(Polly)
# I want it to print
Amy.greeting()
Amy.buy()
Amy.birthday()
THE PROBLEM CODE
Polly.name() # TypeError: 'str' object is not callable
Two.name(Polly)# Works. Why?
Why does calling the method on the class instance Polly not work? I'm pretty lost. I've looked at http://mail.python.org/pipermail/tutor/2003-May/022128.html and other Stackoverflow questions similiar to this, but I'm not getting it. Thank you so much.