472,353 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 608

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Frank Millman | last post by:
Hi all I want to control the assignment of a value to an attribute. Instead of allowing it to be changed directly, I want to enforce that a...
by: Chris... | last post by:
Two simple questions regarding future of Python: 1) Is there already a "fix" to avoid writing to an attribute that isn't defined yet? I remember...
by: Sarah Tegtmeier | last post by:
Hi I have a question about the correct use of the attribute xsi:schemaLocation. My programm has to process XML files where the value of this...
by: j erickson | last post by:
with the following xsl and xml file, the display of the gif file with the <image/url> tag works. However, the gif file in the <description> tag...
by: Ally | last post by:
Could someone give me an example of a modern development methodology? Just to see if I'm thinking along the right lines... P.S. Sorry for the...
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object...
by: globalrev | last post by:
wassup here? 7 Traceback (most recent call last): File "C:\Python25\myPrograms\netflix\netflix.py", line 22, in <module> print...
by: Gabriel Rossetti | last post by:
Hello everyone, I had read somewhere that it is preferred to use self.__class__.attribute over ClassName.attribute to access class (aka static)...
by: Tim Cook | last post by:
Say I have these classes: class Parent(object): """Parent is abstract""" a=None def showA(): return self.a class Child(Parent):...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.