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

2017-02-23 Thread Steven D'Aprano
On Thu, Feb 23, 2017 at 09:40:14PM +1100, Steven D'Aprano wrote: > How do instance attributes normally get set? In the __init__ method: > > class MyClass: > def __init__(self): > self.attribute = None > > > If the __init__ method does get run, it doesn't get the chance to create >

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

2017-02-23 Thread boB Stepp
On Wed, Feb 22, 2017 at 10:49 PM, Zachary Ware wrote: > On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp 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()

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

2017-02-23 Thread boB Stepp
Thank you to everyone that provided illumination in this thread! Things seem much clearer now, which caused me to realize that what I wrote below cannot work as written (Even though I did copy and paste it from the interpreter): On Wed, Feb 22, 2017 at 10:53 PM, boB Stepp wrote: > On Wed, Feb 22,

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

2017-02-23 Thread Steven D'Aprano
On Wed, Feb 22, 2017 at 10:25:58PM -0600, boB Stepp wrote: > I am trying to wrap my head around the mechanics of inheritance in > Python 3. Here is a simplified picture of how inheritence usually works in Python. For an instance `spam`, when you look up an attribute (which includes methods), Pyt

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

2017-02-23 Thread Alan Gauld via Tutor
On 23/02/17 04:25, boB Stepp wrote: > I am trying to wrap my head around the mechanics of inheritance in > Python 3. I thought that all attributes of a superclass were > accessible to an instance of a subclass. For class attributes that happens automatically. >>> class A: a = 'A'

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

2017-02-23 Thread Steven D'Aprano
On Wed, Feb 22, 2017 at 10:25:58PM -0600, boB Stepp wrote: > I am trying to wrap my head around the mechanics of inheritance in > Python 3. I thought that all attributes of a superclass were > accessible to an instance of a subclass. But when I try the > following: > > py3: class A: > ... de

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

2017-02-23 Thread Peter Otten
boB Stepp wrote: > On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp > wrote: >> I am trying to wrap my head around the mechanics of inheritance in >> Python 3. I thought that all attributes of a superclass were >> accessible to an instance of a subclass. But when I try the >> following: >> >> py3: c

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

2017-02-22 Thread Alex Kleider
On 2017-02-22 20:53, boB Stepp wrote: On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp wrote: I am trying to wrap my head around the mechanics of inheritance in Python 3. I thought that all attributes of a superclass were accessible to an instance of a subclass. But when I try the following: py3:

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

2017-02-22 Thread boB Stepp
On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp wrote: > I am trying to wrap my head around the mechanics of inheritance in > Python 3. I thought that all attributes of a superclass were > accessible to an instance of a subclass. But when I try the > following: > > py3: class A: > ... def __init

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

2017-02-22 Thread Zachary Ware
On Wed, Feb 22, 2017 at 10:25 PM, boB Stepp wrote: > I am trying to wrap my head around the mechanics of inheritance in > Python 3. I thought that all attributes of a superclass were > accessible to an instance of a subclass. > > Obviously I am horribly misunderstanding something, and being > cur

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

2017-02-22 Thread boB Stepp
I am trying to wrap my head around the mechanics of inheritance in Python 3. I thought that all attributes of a superclass were accessible to an instance of a subclass. But when I try the following: py3: class A: ... def __init__(self): ... self.aa = 'class A' ... py3: class B(A)