1

I have two classes as follows:

class Buttons():
  def __init__(self, dDict):  
    self.TCT = Tool()
    self.dDict = dDict

  def btnName(self):
    # I will use both self.TCT and self.dDict here
    a = self.dDict['setup']

class Switch(Buttons):
  def __init__(self, iButtonType, sButtName=None):
    self.TCT =Tool()
    self.iButtonType = iButtonType
    #sButtName being used below ....

I need to instantiate Switch class, but I need to provide dDict so that Buttons class will have the data it is looking for. What is the right way to instantiate the class Switch? I'm not sure how to handle multiple input parms with default data.

python python-3.x

This other possible solution is not an exact match. Both my classes take input parms and one of the classes has a default value set for its input parm.

usustarr
  • 418
  • 1
  • 5
  • 21
  • Take `dDict` as an additional parameter to `Switch`'s `__init__`, and call `super().__init__(dDict)`? – L3viathan Jun 06 '18 at 13:35
  • Possible duplicate of [How do I initialize the base (super) class?](https://stackoverflow.com/questions/3694371/how-do-i-initialize-the-base-super-class) – MegaIng Jun 06 '18 at 13:36
  • This other possible solution is not an exact match. Both my classes take input parms and one of the classes has a default value set for its input parm. I really am a beginner. So it would be great if you could give me a better code example to get me out of confusion. – usustarr Jun 06 '18 at 13:48

0 Answers0