[pythonvis] Re: Question on classes in Python

  • From: "Joseph Lee" <joseph.lee22590@xxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Thu, 12 Feb 2015 15:18:40 -0800

Hi,

A quick Stack Overflow search says to try:

class grandson(son):

                def foo(self):

                                super(son, self).foo()

The super acts upon the superclass of the first argument. For example, in
the program fragment above, we might have:

class father(object):

                Pass

 

class son(father):

                Pass

 

class grandson(son):

                pass

 

So if we call super on grandson, we'd access attributes of the son class,
but if we call super against the son, the grandson will ask his grandfather
to show his attributes.

 

As for subclasses being submarines and such, I guess a related question is,
"is there a superclass of superheroes?" (laughs)

 

Cheers,

Joseph

From: pythonvis-bounce@xxxxxxxxxxxxx [mailto:pythonvis-bounce@xxxxxxxxxxxxx]
On Behalf Of Jeffrey Thompson
Sent: Thursday, February 12, 2015 1:52 PM
To: pythonvis@xxxxxxxxxxxxx
Subject: [pythonvis] Question on classes in Python

 

                Hello boa constricters! ... No that's not quite right, hmmm
... Pythonistas!,

 

 

                Question for Python group on 2-11-15

                These questions are about class inheritance.

If you don't understand this stuff below, start by reading Richard's slices
of Py by reading the "class" slices in the order that they have been posted.

The slice of Py series by Richard Dinger has been starting to get into
classes. 

"Inheritance" may become available shortly with descriptions and examples.

A couple of questions on inheritance in classes in python.

 

How does one access the items in a grandfather class in the hierarchy,

e.g.: class Jobs to do -> Dirty Jobs to do -> dirty and smelly jobs to do;

Which means that Dirty Jobs to do inherits from Jobs to do.

and Dirty and Smelly Jobs to do inherits

Dirty Jobs to do.

 

I know that dirty and smelly jobs to do can use the keyword "super" to
access the class dirty jobs to do;

but how does one access class "Jobs to do" from class Dirty and smelly jobs?


 

Would it be super(super) ?

Or do you need the name of the grandfather class?

 

2)Important follow-up questions

Is a subclass a class for submarines?

And what if you would like to inherit a class that's good but not really
super?

 

                Jet (Jeff Thompson

                

 

                

 

                

 

                

Other related posts: