I'm a newbie to Python and I'm looking for a way to write a class with many optional properties, that can be initialized in a single code line.
What I've found so far is the approach of optional parameters to the init method which can be assigned by name:
class MyClass():
def __init__(self, param1=None, param2=None, param3=None, param4=None):
self.param1 = param1
self.param2 = param2
self.param3 = param3
self.param4 = param4
And the initialization can look like:
o1 = MyClass(param2="someVal", param4="someOtherVal")
This approach seems fine, plus I think an IDE like IntelliJ will be able to supply some code completion in this style.
However, I wonder if this is the right approach in case I will create a complex class hierarchy. Let's say that MyClass will inherit from MyBaseClass and MyOtherClass and I wish to initialize all the properties from all the classes through the init method of MyClass(or some other way?).
What's the best way to accomplish this, hopefully with still helping the IDE to be able to provide code completion?
Thanks for the help.