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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:54:10+00:00 2026-06-10T03:54:10+00:00

In the following sample, is there a magic word I can put in place

  • 0

In the following sample, is there a magic word I can put in place of <ChildClass> that works like the opposite of super?

class Parent(object):

    def __init__(self):
        print <ChildClass>.x

class someChild(Parent):
    x = 10

It is a stupid example, but it shows my intention. By the way, using someChild will not work, because there are many child classes.

The only solution I can think of is to have a constructor in every child class that calls the constructor of Parent with a reference to itself (or even to pass x), but I would like to avoid having a constructor at all in each child.

  • 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-10T03:54:12+00:00Added an answer on June 10, 2026 at 3:54 am

    What is wrong with just using self.x?

    class Parent(object):
        x = None  # default value
        def __init__(self):
            print self.x
    
    class someChild(Parent):
        x = 10
        def __init__(self):
            Parent.__init__(self)
    
    class otherChild(Parent):
        x = 20
        def __init__(self):
            Parent.__init__(self)
    
    a = someChild()
    # output: 10
    b = otherChild()
    # output: 20
    

    Note how this works even if Parent has a class attribute x as well (None in the above example)- the child’s takes precedence.

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

Sidebar

Related Questions

I have data in a table that looks like the following sample data: varchar(20)
I have the following String Sample however in some occurences there may be one
http://jsfiddle.net/SXrAb/ Following the jsfiddle link there is a simplified sample of what I need.
I have the following sample code and noticed that if I attempt to use
I wrote the following sample code to see how ARC works @property (nonatomic, weak)
I have the following sample code. class bar is derived from the base class
given the following sample table structure is there a way to add to a
If you run the following sample code in SQL Server, you'll notice that newid()
I have the following sample code that zooms each time a button is pressed:
Given the following sample form code and CSS stylesheet Form <div class="Center_300 "> <button

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.