Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:47:38+00:00 2026-06-04T01:47:38+00:00

Please help me understand this. I created a really simple program to try to

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:47:39+00:00Added an answer on June 4, 2026 at 1:47 am

    The class Two has an instance method name(). So Two.name refers to this method and the following code works fine:

    Polly = Two()
    Two.name(Polly)
    

    However in __init__(), you override name by setting it to a string, so any time you create a new instance of Two, the name attribute will refer to the string instead of the function. This is why the following fails:

    Polly = Two()      # Polly.name is now the string 'Polly'
    Polly.name()       # this is equivalent to 'Polly'()
    

    Just make sure you are using separate variable names for your methods and your instance variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help with this issue of using NSFetchedResultsController. I created an object of NSFetchedResultsController
Please help me understand this recursive function... var stack = Array; function power(base, exponent){
Please help me. I can't understand why this function, that uses texture memory __global__
Please help me understand 2 things I found in this C code: First, there
Please help me understand why this function throws an exception when it reaches fclose
Please help me understand why add1() and add4() report errors and why add2() and
Please help me understand where I am going wrong so much so that I
the following code is not behaving like I would expect. Please help me understand
Can anyone please help me to understand how should i access json data in
Please could someone help me understand why the div.fl element shown in Developer Tools

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.