469,955 Members | 1,878 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,955 developers. It's quick & easy.

Re: Correct Attribute Assignment Methodology?

Tim Cook wrote:
Say I have these classes:

class Parent(object):
"""Parent is abstract"""
def showA():
return self.a

class Child(Parent):
"""inherits a and showA from Parent"""

def __init__(self,a,b):

def showAB():
return self.a,self.b
class GrandChild(Child):
"""inherits all of the above"""

def __init__(self,a,b,c):
"""should this be Child.__init__(a,b)? or Child.__init__(b)?""
Child.__init__(self,a,b) # requires all three params.
"""if so; why? if not why not?"""
In this simple case, I would probably do what you did. But a reason to
call the baseclass init would be to not repeat yourself and keep the
derived class in sync. Suppose, for instance, Child.__init__ had
'self.frob = math.sin(a) + math.cos(b) - math.sqrt(a*a+b*b)', and then
you realize that the formula needs to be changed. Better to have it in
one place.

Thanks for answering these very basic questions but I am not certain
about the correct way. I know that in Python, assignment in the
GrandChild class will work but is that correct?
Jul 30 '08 #1
0 570

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Frank Millman | last post: by
reply views Thread by Sarah Tegtmeier | last post: by
22 posts views Thread by Ally | last post: by
13 posts views Thread by globalrev | last post: by
18 posts views Thread by Gabriel Rossetti | last post: by
reply views Thread by Tim Cook | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.