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"""
a=None
def showA():
return self.a

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

def __init__(self,a,b):
self.a=a
self.b=b

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

def __init__(self,a,b,c):
self.a=a
self.b=b
"""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.
self.c=c

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

7
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...
6
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...
0
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...
1
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...
22
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...
5
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...
13
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...
18
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)...
0
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):...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
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...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
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. ...
0
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...
0
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...
0
hi
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...
0
Oralloy
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...
0
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.