Is there a more pythonic way to have multiple defaults arguments to a class?
<p>I have a class with many defaults since I can't function overload. Is there a better way than having multiple default arguments, or using kwargs? </p>

<p>I thought about passing a dictionary in to my class but then how do I control whether or not the necessary arguments will be passed in? </p>

<p>If there's a more pythonic way that I should be doing this?</p>

<pre class="lang-py prettyprint-override"><code>class Editor:
    def __init__(self,
                 ffmpeg: str,
                 font_file=None,
                 font_size=148,
                 font_color="white",
                 title_length=5,
                 title_x="(w-text_w)/2",
                 title_y="(h-text_h)/2",
                 box=1,
                 box_color="black",
                 box_opacity=0.5,
                 box_border_width=25):
        self.ffmpeg = ffmpeg
        self.commands = {'help': [self.ffmpeg, '-h']}
        self.command_sequence = []
        self.titles= {"font": {"file": font_file,
                               "size": font_size,
                               "color": font_color},
                      "length": title_length,
                      "box": {"status": box,
                              "color": box_color,
                              "opacity": box_opacity,
                              "borderw": box_border_width},
                      "coordinates": {"x": title_x,
                                      "y": title_y}}
</code></pre>

<p>One way is to use <a href="https://en.wikipedia.org/wiki/Method_chaining" rel="nofollow">method chaining</a>.</p>

<p>You can start with some class setting all (or most) parameters to defaults:</p>

<pre><code>class Kls(object):
    def __init__(self):
        self._var0 = 0
        self._var1 = 1
</code></pre>

<p>Then you add methods for setting each needed one:</p>

<pre><code>    def set_var_0(self, val):
        self._var0 = val
        return self

    def set_var_1(self, val):
        self._var1 = val
        return self
</code></pre>

<p>Now, when you create an object, you can just set the necessary ones:</p>

<pre><code>c = Kls()

c = Kls().set_var_1(2)

c = Kls().set_var_1(22).set_var_0(333)
</code></pre>

<p>Of course, you are not restricted to writing a method that sets a single parameter each time, you could write methods that set small "families" of parameters. These already might have regular default values, if needed.</p>

python class constructor default-arguments