[Tutor] How to access an instance variable of a superclass from an instance of the subclass?

boB Stepp robertvstepp at gmail.com
Thu Feb 23 22:11:37 EST 2017


On Wed, Feb 22, 2017 at 10:49 PM, Zachary Ware
<zachary.ware+pytut at gmail.com> wrote:
> On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp <robertvstepp at gmail.com> wrote:

>
> I'll give you a couple of hints.  First, try this:
>
> print('defining A')
> class A:
>     print('Setting a on class A')

When I typed this in I was surprised to find that the print() happens
without having created an instance of this class yet.  Further
experimentation seems to indicate that all class methods and
attributes get executed and assigned when the class definition is
first read into the interpreter without any need to create an instance
of the class.  This is good to know!

> Next, have a look at
> https://docs.python.org/3/library/functions.html#super and in
> particular the link at the end to Raymond Hettinger's "super
> considered super" essay.

I had actually bookmarked this last week in my browser for later
reading.  I just got finished reading it.  It has brought additional
clarity, but also much more I need to think about and explore.

Thanks, Zach!



-- 
boB


More information about the Tutor mailing list