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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:28:33+00:00 2026-05-22T12:28:33+00:00

I frequently do this sort of thing: class Person(object): def greet(self): print Hello class

  • 0

I frequently do this sort of thing:

class Person(object):
    def greet(self):
        print "Hello"

class Waiter(Person):
    def greet(self):
        Person.greet(self)
        print "Would you like fries with that?"

The line Person.greet(self) doesn’t seem right. If I ever change what class Waiter inherits from I’m going to have to track down every one of these and replace them all.

What is the correct way to do this is modern Python? Both 2.x and 3.x, I understand there were changes in this area in 3.

If it matters any I generally stick to single inheritance, but if extra stuff is required to accommodate multiple inheritance correctly it would be good to know about that.

  • 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-22T12:28:34+00:00Added an answer on May 22, 2026 at 12:28 pm

    You use super:

    Return a proxy object that delegates
    method calls to a parent or sibling
    class of type. This is useful for
    accessing inherited methods that have
    been overridden in a class. The search
    order is same as that used by
    getattr() except that the type itself
    is skipped.

    In other words, a call to super returns a fake object which delegates attribute lookups to classes above you in the inheritance chain. Points to note:

    • This does not work with old-style classes — so if you are using Python 2.x, you need to ensure that the top class in your hierarchy inherits from object.
    • You need to pass your own class and instance to super in Python 2.x. This requirement was waived in 3.x.
    • This will handle all multiple inheritance correctly. (When you have a multiple inheritance tree in Python, a method resolution order is generated and the lookups go through parent classes in this order.)

    Take care: there are many places to get confused about multiple inheritance in Python. You might want to read super() Considered Harmful. If you are sure that you are going to stick to a single inheritance tree, and that you are not going to change the names of classes in said tree, you can hardcode the class names as you do above and everything will work fine.

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

Sidebar

Related Questions

I frequently find myself creating classes which use this form (A): abstract class Animal
I am kinda new to this Regex thing. When analyzing some code I frequently
When creating reports I find myself frequently joining to ad-hock sub queries like this:
How should I implement very fast lookups of items in a collection? class Person(object):
This is something I encounter frequently, but I don't know the elegant way of
I have a table of frequently updated information. This is presented using a container
Calling getActionBar returns null . This has been frequently reported so I've made sure
When retrieving packages with Cabal, I frequently get errors with this message: user error
I frequently use the Remove and sort usings feature of VS/PowerCommands - in fact,
I'm new to rails and making some sort of noob mistake: I frequently need

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.