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 928205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:58:24+00:00 2026-05-15T19:58:24+00:00

I am new to Python and while unit testing some methods on my object

  • 0

I am new to Python and while unit testing some methods on my object I noticed something ‘weird’.

class Ape(object):
    def __init__(self):
        print 'ooook'

    def say(self, s):
        print s

def main():
    Ape().say('eeek')

if __name__ == '__main__':
    main()

I wrote this little example to illustrate where I got confused. If you do Ape().say(‘eeek’) does this actually instantiate an Ape object and run the init method? I thought it wouldn’t but I had some weird side effects so now I am thinking it does?

  • 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-05-15T19:58:25+00:00Added an answer on May 15, 2026 at 7:58 pm

    Yes it does. That’s what Ape() does: it creates an new Ape object, and as part of that process the __init__ method gets run.

    In your example, you then call the say method of that object. Note that there would be no way to call say if you didn’t have an Ape object.

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

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It's as easy as: $('#UseUsername').change(function(){ if($(this).is(':checked')){ $('#div').show(); } else {… May 16, 2026 at 5:45 pm
  • Editorial Team
    Editorial Team added an answer This is possible by using an interface and having the… May 16, 2026 at 5:45 pm
  • Editorial Team
    Editorial Team added an answer You're missing a ( here: echo "Size: " . $img["size"]… May 16, 2026 at 5:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm completely new to Python and while trying various random bits and pieces I've
I am new to Python - be forewarned! I have a template class that
I'm writing a python module and I would like to unit test it. I
While I've written unit tests for most of the code I've done, I only
I have a class that I wish to test via SimpleXMLRPCServer in python. The
I've been trying to learn Python, and while I'm enthusiastic about using closures in
I'm a very new python user (had only a little prior experience with html/javascript
Bit of a weird one: I was told a while ago by a friend
I'm new to python and django, and when following the Django Book I learned
I'm new to Python and I have been trying to search through html with

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.