Suppose I have the following class in Python 3:
class CoolCar:
@classmethod
def myWheels(cls):
cls.Wheels().out()
class Wheels:
def __init__(self):
self.s = "I'm round!"
def out(self):
print(self.s)
All well and good. Now I want a derived class:
class TerribleTank(CoolCar):
class Wheels(CoolCar.Wheels):
def __init__(self):
self.s = "I'm square!!"
This works as I would expect:
CoolCar.myWheels()
TerribleTank.myWheels()
But what's bothering me is that I have to write CoolCar
twice in the definition of TerribleTank
. So I tried this:
class TerribleTank(CoolCar):
class Wheels(super().Wheels):
def __init__(self):
self.s = "I'm square!!"
Which does not work. Now, I know it doesn't work because super()
is looking for a first-argument self
/cls
to begin its search.
So finally my question: Is there something like this that works, so that I don't need to explicitly write that second CoolCar
?
What about:
basically when you inherit
CoolCar
inTerribleTank
, you set upTerribleTank.Wheels
as a reference toCoolCar.Wheels
, until you shadow it with your own new definition of it within theTerribleTank
definition. So I believe that matches your expectations of not havingCoolCar
twice in TerribleBank definition ☺HTH