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

  • Home
  • SEARCH
  • 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 3938264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:09:53+00:00 2026-05-20T00:09:53+00:00

Hope this is clear enough: class myParent(): def __init__( self ): self.parentNumber = 5

  • 0

Hope this is clear enough:

class myParent():
    def __init__( self ):
        self.parentNumber = 5

class Child( myParent ):
    def __init__( self ):
        self.childNumber = 4

    def multiplyNumbers( self ):
        print myParent.parentNumber * self.childNumber

p = Child()
p.multiplyNumbers()

I wish to set the parentNumber individually, and then reach that number via the child class, and in this case use it for some multiplication.

I’m new to the OOP area so any general pointers on inheritance is welcome as well!

More info:
I’m designing a project management solution for vfx-based projects, and am playing with classes and inheritance to see how they can help me the most.

Right now, I’ve got the top class, Project, and a derived class, Shot. Shot has a self.length variable with the length of the specific shot. It’s also got a getLengthInSeconds() method that uses self.length along with the Project.fps to determine the length in seconds. Project has a setFps() method in which the fps is set after an instance of the class is created.

I’m kind of used to variables being prefixed with self. and have not experimented much with classes using the more “global” variables without self. . If I make everything global, no self., I can use Project.fps without hassle, but I’m getting a “bad programming practice” warning in my neckhair. Perhaps there is a better, more neat, way?

Edit:

After some reading, super() seems kinda dangerous, and a bit more than I need I think. I am mainly having single-inheritance classes and aren’t even sure how to make use of diamond hierarchies.. Is there a safer way to access superclass variables and methods that doesn’t include super()?

Edit:

Allright, see if this makes sense or if I’m thinking about it all wrong.

I’m looking at classes and inheritance as groups and children. A child knows it’s parent and all it’s values. A child to another parent knows That parents values. What I’m trying to accomplish is having all shots created be part of a project. And right now, I’m creating Shot() instances from within Project() class, adding the instances to a list of shots which is then maintained within the Project() instance.

i.e.

class myParent( object ):
    def __init__( self ):
        self.parent_id = ''
        self.children = []

    def createChild( self, name ):
        self.children.append( myChild( name ) )

    def getChildren( self ):
        return self.children

    def setParentId( self, id ):
        self.parentId = id

class myChild( myParent ):
    def __init__( self, id ):
        super(myChild, self).__init__()
        self.id = id

    def getParentId( self ):
        return self.parent_id

p = myParent()
p.setParentId( 'parent01' )
p.createChild( 'child01' )
print p.getChildren()[0].getParentId()

I can sort of see the mis-steps in logic here, but no real way around it..
Seems like every child is getting a new instance of the parent this way, where parent_id is always an empty string.

  • 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-20T00:09:53+00:00Added an answer on May 20, 2026 at 12:09 am
    class myParent( object ):
        def __init__( self ):
            self.parentNumber = 5
    
    class Child( myParent ):
        def __init__( self ):
            myParent.__init__( self )
            self.childNumber = 4
    
        def multiplyNumbers( self ):
            print self.parentNumber * self.childNumber
    
    p = Child()
    p.multiplyNumbers()

    You can usually manage just fine without super when you don’t have multiple inheritance or other border cases, although if the base class changes, you will need to remember to change the parent class name from init (and any other method that refers to myParent explicitly).

    If your parent’s __init__ takes parameters, you need to pass them on from the child’s __init__.

    class myParent( object ):
        def __init__( self, customParam ):
            self.parentNumber = 5
            self.customParam = customParam
    
    class Child( myParent ):
        def __init__( self, customParam ):
            myParent.__init__( self, customParam )
            self.childNumber = 4

    If you dislike the repetition of customParam in all child classes, there’s an alternative OO pattern called two phase construction, which works like this:

    class myParent( object ):
        def customInit( self, customParam ):
            self.parentNumber = 5
            self.customParam = customParam
    
    class Child( myParent ):
        def __init__( self, customParam ):
            self.childNumber = 4
    
    p = Child()
    p.customInit(10)
    p.multiplyNumbers()
    

    In this pattern, you don’t need to repeat any of the parent’s parameters, or even call the parent’s __init__ in the child, but the downside is that you will need to remember to always call the secondary constructor when creating objects, or your object will be left partially uninitialized.

    UPDATE (to answer the updated question):

    You seem to be mixing two unrelated concepts of parenthood here. Inheritance is about type hierarchy, and you seem to be after an ownership hierarchy (is-a versus has-a).

    I would structure your updated code like this:

    class myParent( object ):
        def __init__( self, parentId ):
            self.id = parentId
            self.children = []
    
        def createChild( self, name ):
            self.children.append( myChild( name, self ) )
    
        def getChildren( self ):
            return self.children
    
    class myChild( object ):
        def __init__( self, childId, parent ):
            self.id = childId
            self.parent = parent
    
        def getParentId( self ):
            return self.parent.id
    
    p = myParent( 'parent01' )
    p.createChild( 'child01' )
    print p.getChildren()[0].getParentId()
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question here; hope I'll be clear enough... I've got this
The docs at www.fastcgi.com aren't clear on this (to me), so I hope someone
I hope this is a simple enough question for any SQL people out there...
I hope this is close enough to programming to pass the bar :) Is
I hope this question does not come off as broad as it may seem
I hope this question is not considered too basic for this forum, but we'll
I hope this is programmer-related question. I'm in the hobby business of C# programming.
I hope this isn't considered a duplicate since it's more pointed than similar questions
I hope this question is not a RTFM one. I am trying to write
I'm relatively new to web application programming so I hope this question isn't too

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.