[Tutor] How to access an instance variable of a superclass from an instance of the subclass?
Steven D'Aprano
steve at pearwood.info
Thu Feb 23 23:45:03 EST 2017
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
> the instance attributes. So if you have a subclass that defines
> __init__, you need to allow the superclass' __init__ to run too.
/me slaps forehead
Of course I meant to write:
If the __init__ method does NOT get run, it doesn't get the chance to
create the instance attributes.
Sorry for any confusion.
--
Steve
More information about the Tutor
mailing list