-1

I have a class with a member that is a list of another class. So I want something like

class primary_class:
    def __init__(self):
        self.slist = []
    def add_secondary_class(self, <arguments>):
        self.slist.append(secondary_class(<arguments>))

Basically I want to be able to pass add_secondary_class arguments the exact same way I would pass them to the secondary_class constructor.

goi42
  • 55
  • 8

1 Answers1

1
def add_secondary_class(self, *args):
    self.slist.append(secondary_class(*args))

or, if you have kwargs

def add_secondary_class(self, **kwargs):
    self.slist.append(secondary_class(**kwargs))
codelessbugging
  • 2,179
  • 10
  • 19